|
-
Apr 8th, 2002, 06:22 PM
#1
Calling a pointer from a static member
In my class i have a pointer to point to different functions and i want to use that pointer to call the functions from a static member of the class.
I thought something like this would work...
Code:
(pPARENT.*m_pInputOnCharProc)(&wParam);
But it doesnt. I get these errors...
Code:
cdlgmain.cpp(192) : error C2597: illegal reference to data member 'CDlgMain::m_p InputOnCharProc' in a static member function
cdlgmain.cpp(192) : error C2568: '.*' : unable to resolve function overload
pPARENT is the variable thats holding the "this" of the class.
Any ideas?
-
Apr 8th, 2002, 10:19 PM
#2
You cant use any dynamic function or data in a static member. You could make the pPARENT variable static, and assign this to it every time you want to call the static function, but that seems a bit awkward. What are you trying to accomplish?
Z.
-
Apr 8th, 2002, 10:42 PM
#3
What do you mean by dynamic? If you mean any of the non-static functions and variables, then your wrong. I just need the pointer, which i have.
-
Apr 9th, 2002, 08:02 AM
#4
pParent is a pointer, so do:
(pPARENT->*m_pInputOnCharProc)(&wParam);
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Apr 9th, 2002, 08:04 AM
#5
But the pointer is not static, so you cannot access it inside of a static function. Think of it this way. There is only one instance of each static member function and variable for ALL classes. Dynamic functions (non-static) can easily use these functions and variables, because they know where they are stored, etc. But think about it the other way. How does a static function know where a dynamic variable is stored? Which one should it use? If I have 15 instances of some class, which one's pPARENT should I look at? So, you cannot access non-static members from a static member. It is impossible, unless you pass in a this pointer to the function (in which case, it shouldnt be a static function).
Z.
-
Apr 9th, 2002, 08:10 AM
#6
I guess pPARENT is maybe a static member (bad idea) or a function parameter (also bad idea, like Zaei said, function should be normal method then).
Or it is a pointer casted to the base class...
Or this is a windows callback and pPARENT is casted from the lparam. (Actually the most probable, the name of the function pointer member indicates a WNDPROC)
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|