|
Hi,
thank you for your answer.
I try same solution as you send me, but I have another problem:
MyOwner and MyClient classes are in their separate header files ( MyOwner.h and MyClient.h). If I try use this solutin, I got many errors from compiler.
I think that problem may be in incorrect includes of header files.
Can somebody give me some advice?
Regards
Radek
|
|
|
|
|
You must use a forward declaration:
Inside MyOwner.h
class MyClient;
class MyOwner
{
.
.
.
}
Inside MyClient.h
class MyOwner;
class MyClient
{
.
.
.}
“Cannot find REALITY.SYS...Universe Halted.”
~ God on phone with Microsoft Customer Support
|
|
|
|
|
Discalimer:
The cluttered design of the following code is a mere conseguence of you requirements and
you retain full responsibility of
(I need the above to escape from led mike's advices about Scott Meyers' books )
class MyOwner;
class MyClient
{
MyOwner * m_pOwner;
public:
MyClient(MyOwner * pOwner):m_pOwner(pOwner){}
void doStuff();
};
class MyOwner
{
friend class MyClient;
private:
int m_iHiddenSecret;
public:
MyOwner (int iTheSecret)
{
m_iHiddenSecret = iTheSecret;
m_pClient = new MyClient(this);
}
~MyOwner()
{
delete m_pClient;
}
MyClient * m_pClient;
};
void MyClient::doStuff()
{
cout << "Now we all know the secret is: " << m_pOwner->m_iHiddenSecret << endl;
}
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
modified on Friday, October 24, 2008 3:28 AM
|
|
|
|
|
I was just wondering what were some tutorials out there that do a good job of explaining functions and how they work? If you could please post a link that would be greatly appreciated!
|
|
|
|
|
There's Wikipedia [^], for instance.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Function Tutorials[^]
“Cannot find REALITY.SYS...Universe Halted.”
~ God on phone with Microsoft Customer Support
|
|
|
|
|
Wow - you provide "about 530,000" links and you get voted down.
Tough room!
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark Salsbery wrote: Tough room!
Yes, Tough is the new Stupid!
led mike
|
|
|
|
|
Hello Everyone
i am trying to get color of the pixel from the monitor by using the below code but i getting 0xFFFFFFFF value every time wherever i click whether black,red green or white color its giving me same value, so can anybody help me out
the code is like this:
void getpixelcolor(CPoint point){
COLORREF m_colCurrent = pDesktopDC->GetPixel(point);
BYTE rVal = GetRValue(m_colCurrent);
BYTE gVal = GetGValue(m_colCurrent);
BYTE bVal = GetBValue(m_colCurrent);
}
regards
rakesh
|
|
|
|
|
Hello Everyone
i am trying to get color of the pixel from the monitor by using the below code but i getting 0xFFFFFFFF value every time wherever i click whether black,red green or white color its giving me same value, so can anybody help me out
the code is like this:
void getpixelcolor(CPoint point){
COLORREF m_colCurrent = pDesktopDC->GetPixel(point);
BYTE rVal = GetRValue(m_colCurrent);
BYTE gVal = GetGValue(m_colCurrent);
BYTE bVal = GetBValue(m_colCurrent);
}
regards
rakesh
|
|
|
|
|
the following code (just a quick test) is working fine on my system
HDC hDC = ::GetDC(NULL);
int x,y;
x = rand() % 600;
y = rand() % 600;
COLORREF cr = GetPixel(hDC, x, y);
CString szMsg;
szMsg.Format(_T("(%d %d) = { %d, %d, %d}"), x,y, GetRValue(cr), GetGValue(cr), GetBValue(cr));
AfxMessageBox(szMsg);
::ReleaseDC();
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
i am using CRichEditCtrl, and sending to the control the EM_AUTOURLDETECT message.
problem is the rich edit decides the text color of the hyper link
how to change it?
thanks in advanced
Yaron
Interface basics click here :
http://www.codeproject.com/com/COMBasics.asp
don't forget to vote
|
|
|
|
|
Hi,
Currently im working on MFC Dialog Based application, the design of the dialog is to let user key in the word, then my picture control will render the sign language using the OpenGL. So I would like to link up the capture words that user key in the dialog and pass it to another function in order to display the animation. The problem now is Im unable to pass the variable from dialog.cpp to OpenGL.cpp
the dialog.cpp indicate that the dialog based that i have created while the OpenGL.cpp indicare that the program that I wrote to render the model.
I had declared the global variable as extern int NumOfWords and extern CString Word[20].
the NumOfWords is to capture how many words that user had keyed in and the CString Word[20] is to store the word by word into array.
How am I going to make these two variable at OpenGL.cpp? Hope to hear from you all soon. thank you.
regards,
sn00pi
|
|
|
|
|
sn00pi wrote: How to declare global variable in MFC dialog based application?
Like in any other C++ application (see [^]).
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Hi,
After declare the global Variable, how come the variable cannot be passing down to other .cpp? global variable should be able to passing down the variable right?
After I entered the word, the system able to capture the word. but then the word that store in the array unable to pass to the OpenGL.cpp is there any solution to solve this problem? thank you.
regards,
sn00pi
|
|
|
|
|
I think you should post the relevant pieces of code (stating the header or source file each snippet belongs to) and the detailed error messages you get (if any).
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
hi,
here is it the oglMFCDialog.cpp code which is the dialog, when the user enter word, after click on button, the button function as below:
m_sText2 = m_sText;
m_sText = " ";
CString str = m_sText2;
int NumOfWords=0;
CString Word[20];
int c=0;
CString word;
int curPos= 0;
word = str.Tokenize(",.?% #",curPos);
while (word != "")
{
Word[NumOfWords]= word;
NumOfWords = NumOfWords + 1;
word = str.Tokenize(",.?% #",curPos);
}
COpenGLControl::COpenGLControl();
here is OpeGLControl.cpp file for OpenGL rendering,
COpenGLControl::COpenGLControl()
{
int NumOfWords;
CString Word;
static int t=0;
for(int a=0;a<NumOfWords; a++)
{
for(int c=0;c<NumOfFramesLoad;c++)
{
if(c == NumOfFramesLoad - 1)
{
g_3DModel[t] = g_3DModel[0];
}
else
{
string ObjFile[100];
char g ='0'+ c;
ObjFile[t] = Word[a] + g + ".obj";
........
........
The global variable i define in the OpenGLControl.h
extern int NumOfWords;
extern CString Words[20];
Those i need to used this 2 variables .cpp file i have declare them. Hope to hear from you soon. thank you.
regards,
sn00pi
|
|
|
|
|
sn00pi wrote: COpenGLControl::COpenGLControl()
{
int NumOfWords;
This local variable declaration hides the global one in the contex. remove it.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
I am new to C++
Consider the following
int number = 5;
int *numptr = &number;
Herecan say, numptr is a pointer to an integer and it has the address of the location where 5 is stored
char * number = "five is number";
However here is it right to say that the 'number' is a pointer to a char and stores the address of the first character in the string(f). If it is, then why does the statement,
cout<<number;
gives the string itself as the output and not the address where the character 'f' is stored.Also what does '&number' mean when 'number' is a pointer.
|
|
|
|
|
Because the '<<' operator in the ostream class has many implementations.
Which one of the implementations is called depends on the arguments in call.
Functions like this are referred to as homonymous, if I recall correctly.
This means that if you call the operator and provide an integer as argument the value will be sent to the stream. If you provide a char* it is assumed to point to a zero-terminated string and will send all characters beginning with the address pointed to and stopping when a NULL char is detected.
Read more about the ostream::operator<<() here[^].
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
rahulcrjk wrote: gives the string itself as the output and not the address where the character 'f' is stored
Because the << operator was overloaded for the char* type and it is implemented to display the string itself. STL provided overloads for a lot of different types and they implemented the way they like (here, it makes much more sense to output the string and not its address).
rahulcrjk wrote: Also what does '&number' mean when 'number' is a pointer.
I don't really understand what you mean but I guess you are asking what &numptr means (if I use the code you provided earlier) ? In that case it simply means that it is the address of the pointer (remember that pointers are variables too, so they also have an address, which can be stored in another variable, and so on ad infinitum ).
|
|
|
|
|
rahulcrjk wrote: Herecan say, numptr is a pointer to an integer and it has the address of the location where 5 is stored
good.
rahulcrjk wrote: char * number = "five is number";
However here is it right to say that the 'number' is a pointer to a char and stores the address of the first character in the string(f). If it is, then why does the statement,
cout<<number;
gives the string itself as the output and not the address where the character 'f' is stored.
Because:
(1) the string layout in memory is
ADDRESS VALUE
number 'f'
number + 1 'i'
number + 2 'v'
number + 3 'e'
number + 4 ' '
number + 5 'i'
number + 6 's'
number + 7 ' '
number + 8 'a'
number + 9 ' '
number + 10 'n'
number + 11 'u'
number + 12 'm'
number + 13 'b'
number + 14 'e'
number + 15 'r'
number + 16 '\0'
(2) the extraction operator << knows about (1).
rahulcrjk wrote: Also what does '&number' mean when 'number' is a pointer.
is the address of the variable who holds the pointer. For instance
int i;
int * p;
int * * pp;
int k;
i = 5;
p = &i;
pp = &p;
k = **pp + 2;
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
hoo ho, i get your question right, and you have no idea how i struggled with c++ before i coluds understand pointers, thats why they even made java, to eliminate the whole thing about pointers, but the minute you understand the, thats it..
Just know that pointers yes have 2 major refences or usage in c++.
It all depends on how you use them, but fact is , they do point to an address in memory, not the actual data.
Your question goes like this,
if i say
int my_number = 5;
int* my_pointer = #
the output ;
cout << my_pointer ; displays an address, sth like 45542945;
if i output ;
cout << *my_pointer; then i get the number 5;
this is to say, my_pointer, is a memory (RAM) address, and the value in *my_pointer is the value 5;
if when used with a character / string, the pointer will refence the address of the first character, then when i say
char* my_ptr = "this is a string";
cout <<my_ptr.
my pointer being an address of the 1st character, then i shoudl see the address output, not the whole string.
but thats not the case, why??? was that the question.
okay, one point you have right, the other point you are missing is that, a pointer when used to refence an array, it points to the first element of the array.
why do you think this is correct;
int nums[3] = {11,21,31};
int* nums_ptr = nums;
cout<< nums_ptr[0] ;
because when you do point an array (a string is a also an array), you can copy the whole array into a pointer one time.
and yuo know that an array is placed in (contigous) continuous memory locations, i.e. if 11 is in addres x, then 21 is in x+1, and 31.
so for integers if you want the third element of the array in that has been copied to an pointer, if you say nums_ptr[2], you wont get the address of the 3rd element, you'll get the value.
but again for integers if you say
cout<<nums_ptr;
you wont get all the elements of the array displayed on the screen like 112131, no, you get the address.
thats the only differents with characters since, an array of characters is treated like a string..
displaying the pointer wont display the adress of the fisrt character but the whole string.
try play with pointers, that's the weak and stronghold with c++, in that learning is abit confusing but once learnt it gives some crazy flexibility you wont get from any of it's neighbors..
|
|
|
|
|
1. I am using a std::map to store some values of keys
2. On startup of my function i am loading values to my map
3. I am storing values to my map by a http call which is returning the key and values from a file.
4. Now i have changed my configuration file and i want to reload the config map without restarting my process
5. lots of places i am already accessing this map
How safely i can reload my configurations?
Please need some idea and help
Regards,
Samba
|
|
|
|
|
Soumyadipta wrote: 4. Now i have changed my configuration file and i want to reload the config map without restarting my process
5. lots of places i am already accessing this map
How safely i can reload my configurations?
With the limited information you've given at least I can only give a general answer...
You have to trigger the "reloading" procedure in some way.
If you by "accessing the map" mean that you're using the map from different threads, you also need to provide thread synchronization using a critical section or mutex.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|