Click here to Skip to main content
16,012,082 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Casting thread functions Pin
Todd Wilson24-Feb-01 15:20
Todd Wilson24-Feb-01 15:20 
GeneralRe: Casting thread functions Pin
Tim Deveaux24-Feb-01 15:32
Tim Deveaux24-Feb-01 15:32 
GeneralRe: Casting thread functions Pin
Erik Funkenbusch26-Feb-01 12:55
Erik Funkenbusch26-Feb-01 12:55 
GeneralRe: Casting thread functions Pin
Todd Wilson26-Feb-01 13:13
Todd Wilson26-Feb-01 13:13 
GeneralRe: Casting thread functions Pin
Erik Funkenbusch26-Feb-01 13:32
Erik Funkenbusch26-Feb-01 13:32 
GeneralRe: Casting thread functions Pin
Joe Moldovan24-Feb-01 17:44
Joe Moldovan24-Feb-01 17:44 
GeneralRe: Casting thread functions Pin
Tim Deveaux25-Feb-01 5:13
Tim Deveaux25-Feb-01 5:13 
GeneralRe: Casting thread functions Pin
Erik Funkenbusch26-Feb-01 13:11
Erik Funkenbusch26-Feb-01 13:11 
I see you've already recieved answers to your questions, but I thought I would just cover the basic reasons why this is the case.

In C++, member functions do not have the same function signature as a non-member function except (in most cases) when the member function is static. I say in most cases because this is a compiler dependant implementation issue and is undefined in the standard, however the logical way to implement it is the way most compilers do (including VC).

C++ member functions pass a hidden first parameter called "this". When you call an object, it's translated to a different syntax so that the real call looks as so:
object.func();
is really called this way:
class::func(class* const this);  // const pointer to a non-const class
So in reality, all member functions are non-member functions that are namespace qualified and pass a hidden first parameter that allows the function to know where it's instance data is. Something else most people don't realize is that a function that's declared const, such as:
void dosomething(void) const;
is called this way:
void class::dosomething(class const * const this); // const pointer to a const class
This means that if you manage to hoodwink the compiler into compiling a non-member function pointer into a member function pointer, you're going to corrupt the stack. It also explains why when you pass the object instance as the parameter to function, it instead allowed it to be used for "this"; a lucky hack that is bound to break eventually.

So, in closing. Member function pointers and non-member function pointers are not the same type, even if they look like it.
GeneralRe: Casting thread functions Pin
Joe Moldovan26-Feb-01 19:45
Joe Moldovan26-Feb-01 19:45 
QuestionHow to use handle_wm_notify macro which comes with win32? Pin
Sachin23-Feb-01 23:04
Sachin23-Feb-01 23:04 
AnswerRe: How to use handle_wm_notify macro which comes with win32? Pin
Sardaukar24-Feb-01 1:23
Sardaukar24-Feb-01 1:23 
GeneralOnSize Pin
Starodubtsev Sergey23-Feb-01 22:53
Starodubtsev Sergey23-Feb-01 22:53 
GeneralRe: OnSize Pin
Erik Funkenbusch26-Feb-01 13:17
Erik Funkenbusch26-Feb-01 13:17 
Generaltitle text on the main frame Pin
Starodubtsev Sergey23-Feb-01 22:20
Starodubtsev Sergey23-Feb-01 22:20 
GeneralRe: title text on the main frame Pin
Christian Graus23-Feb-01 22:23
protectorChristian Graus23-Feb-01 22:23 
Generalcreate an exe file from another Pin
Sachin23-Feb-01 15:01
Sachin23-Feb-01 15:01 
GeneralRe: create an exe file from another Pin
Tim Deveaux24-Feb-01 4:14
Tim Deveaux24-Feb-01 4:14 
QuestionHow to install source patch with VC++? Pin
23-Feb-01 13:09
suss23-Feb-01 13:09 
QuestionHow to install source patch with VC++? Pin
23-Feb-01 13:08
suss23-Feb-01 13:08 
GeneralWinsock problem - PLEASE help Pin
23-Feb-01 11:11
suss23-Feb-01 11:11 
GeneralRe: Winsock problem - PLEASE help Pin
Tim Deveaux23-Feb-01 13:06
Tim Deveaux23-Feb-01 13:06 
GeneralRe: Winsock problem - PLEASE help Pin
James R. Twine27-Feb-01 8:14
James R. Twine27-Feb-01 8:14 
QuestionSounds ?? Pin
23-Feb-01 8:39
suss23-Feb-01 8:39 
AnswerRe: Sounds ?? Pin
Christian Graus23-Feb-01 22:29
protectorChristian Graus23-Feb-01 22:29 
AnswerRe: Sounds ?? Pin
23-Feb-01 23:34
suss23-Feb-01 23:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.