CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2003
    Posts
    162

    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 :
    error C2352: 'CmdView::get_ABC' : illegal call of non-static member function
    for using CmdView::get_ABC(); in the other class function.

    Thanks a lot.
    Last edited by ayumi; September 12th, 2003 at 09:46 PM.
    0 error(s), 0 warning(s)

  2. #2
    Join Date
    Aug 2003
    Posts
    162
    oops done with it ;x
    0 error(s), 0 warning(s)

  3. #3
    Join Date
    Sep 2001
    Location
    San Diego
    Posts
    2,147
    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:
    Code:
    CmdView MyCmdView;
    
    MyCmdView.get_ABC();
    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,

    - Nigel

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured