illegal call of non-static member function 
Author Message
 illegal call of non-static member function

I am getting error C2352, 'CInboxView::reload_menu' : illegal call of
non-static member function on a function call I am making.  I understand
that this happens when you try to call a non-static function from a
static function, and I have been able to get rid of it by making the
called function static.  The problem is that I don't understand why it
thinks that the *calling* function is static.  Here is the code,
stripped down but not much:

_____________________________________________
//alias.h
#ifndef _alias_h_
#define _alias_h_

#include <spr_common.h>
#include <cmmenu.h>

void build_alias_menu(CmMenu* mainMenu);
void alias_selected(char* value);

#endif
_____________________________________________
//      alias.cpp
#include <stdafx.h>
#include <alias.h>
#include <inboxview.h>

void build_alias_menu(CMenu* mainMenu)
{
   //destroy existing Aliases menu and rebuild
   {
      Bunch of code to redo the menu
   }

Quote:
}

void alias_selected(char* value)
{
   CInboxView::reload_menu(main_info->alias); //THIS IS THE PROBLEM
Quote:
}

_______________________________________________

It's that last line where I call reload_menu that causes the error, but
I don't understand why it thinks that alias_selected() is a static
function, and thus that it cannot call a non-static member function.
Can someone enlighten me?  

(inboxview is your basic view class, and the only thing that I have left
out I believe is where I #include the definition of main_info which is
basically a global structure with a bunch of information in it.)

Melissa Appleby



Tue, 13 Mar 2001 03:00:00 GMT  
 illegal call of non-static member function
Melissa,

My own grasp of this is tenuous, but I'll give it a shot.

Quote:
>I am getting error C2352, 'CInboxView::reload_menu' : illegal call of
>non-static member function on a function call I am making.  I understand
>that this happens when you try to call a non-static function from a
>static function, and I have been able to get rid of it by making the
>called function static.  The problem is that I don't understand why it
>thinks that the *calling* function is static.
>void alias_selected(char* value)
>{
>   CInboxView::reload_menu(main_info->alias); //THIS IS THE PROBLEM
>}
>_______________________________________________

I don't think that the problem has to do with whether or not the
calling function is static.  I think that it has to do with the way in
which you are calling reload_menu().

alias_selected() does not appear to be a member of CInboxView::.
Therefore, to call any member function of CInboxView::, you must
either 1) do so by referencing an instantiation of that class:

void alias_selected(char* value)
{
   CInboxView myView;

   myView.reload_menu(main_info->alias);

Quote:
}

or

void alias_selected(char* value, CInboxView *myView)
{
    myView->reload_menu(main_info->alias);

Quote:
}

or 2) declare reload_menu() as static so that it can be called outside
any specific instantiation of the class (I'm not sure that's
technically correct, but I think it accurately describes the results).

Chip

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
"Make it idiot-proof and someone will make a better idiot."
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

Remove NO and SPAM from my email address.



Tue, 13 Mar 2001 03:00:00 GMT  
 illegal call of non-static member function

Quote:

>Melissa,

>My own grasp of this is tenuous, but I'll give it a shot.

>>I am getting error C2352, 'CInboxView::reload_menu' : illegal call of
>>non-static member function on a function call I am making.  I understand
>>that this happens when you try to call a non-static function from a
>>static function, and I have been able to get rid of it by making the
>>called function static.  The problem is that I don't understand why it
>>thinks that the *calling* function is static.

>>void alias_selected(char* value)
>>{
>>   CInboxView::reload_menu(main_info->alias); //THIS IS THE PROBLEM
>>}
>>_______________________________________________

>I don't think that the problem has to do with whether or not the
>calling function is static.  I think that it has to do with the way in
>which you are calling reload_menu().

>alias_selected() does not appear to be a member of CInboxView::.
>Therefore, to call any member function of CInboxView::, you must
>either 1) do so by referencing an instantiation of that class:

[SNIP]

I think it would be better to make alias_selected() a member of CInboxView
or whatever class it belongs to. You don't really want global functions in
C++.

void CSomeClass::alias_selected(char *value)
{

Quote:
}

-----------------------------------------------------
_ _     Jason Teagle
o o

 V      http://www.teaglehouse.demon.co.uk/home.htm
-----------------------------------------------------


Tue, 13 Mar 2001 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. illegal call of non-static member function

2. illegal call of non-static member function

3. illegal call of non-static member function *HELP*

4. illegal call of non-static member function

5. Illegal call of non-static member function (error)?

6. Error C2352 - illegal call of non-static member function

7. Compiler Error C2352: illegal call of non-static member function

8. illegal call of non-static member function

9. Nothing declared as static but: illegal call of non-static member function...

10. "illegal call of non-static member function"

11. CWnd::GetClientRect' : illegal call of non-static member function

12. Compiler Error C2352:<Function_Name> illegal call of non-static member function

 

 
Powered by phpBB® Forum Software