September 12th, 2003, 10:38 PM
Accessing protected function
How can i access a protected member function in other class??
afx_msg void OnABC();
I need to access this function from other class. Any methods?
I tried to use a public function to access it.
But i got an error :
for using CmdView::get_ABC(); in the other class function.
error C2352: 'CmdView::get_ABC' : illegal call of non-static member function
Thanks a lot.
Last edited by ayumi; September 12th, 2003 at 10:46 PM.
0 error(s), 0 warning(s)
September 12th, 2003, 10:57 PM
September 12th, 2003, 11:03 PM
It looks like the error is due to your use of the class name instead of the object name when accessing the function rather than any protected nature of the function.
Protected functions are exactly that, they are protected from other classes accessing them.
To address your current issue, the calling code seems to be at fault.
You should call the function using the object reference as shown here:
The way you are calling the function (accessing the class directly) makes the compiler assume it is a static function that can exist without the need for an object of that type being created. In this (rare) case you would declare the function static - but I strongly believe this is not what you are trying to do, so you should therefore avoid making the function static.
If you need more help, post a snippet of your code where you are calling this function and clearly indicate which functions are declared protected and which are declared public.
Also, what you are trying to do by making this function call would help.
Hope this helps,
Click Here to Expand Forum to Full Width