can anyone help me in solving this error C2352 - illegal call of a Non-static member

This is a discussion on can anyone help me in solving this error C2352 - illegal call of a Non-static member within the C++ Programming forums, part of the General Programming Boards category; The main function of my program is to realize a client base to the physical Robot and it receives the ...

  1. #1
    Registered User
    Join Date
    Mar 2008
    Posts
    2

    Post can anyone help me in solving this error C2352 - illegal call of a Non-static member

    The main function of my program is to realize a client base to the physical Robot and it receives the parameters from the robot. after some processing it links to the webot environment for visual display. so i have used a two classes with the member functions. i have given the code below. i have a class called mywebot, where the client base is initialized and the class called Output handler where it polls the robot from the clientbase and receives the data from the robot. i have given the code below. here i am linking two environments ARIA and Webot.

    webot.h


    Code:
    class myWebot{
    public:
    	myWebot();
    	 myWebot(ArClientBase *xclient, int argc, char **argv);
    	 static void myWebotReset();
      	 static int myWebotRun(int index);
    	 ArClientBase * getMyArClientBase();
    Protected:
            ArClientBase *myclient;
    };

    handler.h

    Code:
    class OutputHandler
    {
    public:
      OutputHandler(ArClientBase *client);
      virtual ~OutputHandler(void);
    
    protected:
         ArClientBase *myClient;
    };

    webot.cpp

    Code:
    ArClientBase * myWebot::getMyArClientBase(){
    	return myClient;
    }
    
    int myWebot::myWebotRun(int ms)
    
    {
       OutputHandler outputHandler(getMyArClientBase());  
    
    
       while (getMyArClientBase()->getRunningWithLock())
    
      {
      
       }
    }
    
    int mainLoop ()
    {
    	
    	robot_live(myWebotReset);
        robot_run(myWebotRun);
    	
    	return 0;
    }

    Code:
    int main (int argc, char **argv)
    {
    	ArClientBase *client =new ArClientBase();
        myWebot *mw = new myWebot(client,argc,argv);
    
        mw->mainLoop();
    	return 0;
    }
    when i am building the project with the above codes, the compiler gives me the following error the highlighted places (i.e Bold line)

    c:\my_Proj\webotclient\controllers\webotclient\web ot.h(43) : see declaration of 'myWebot::getFlag'
    c:\my_Proj\webotclient\controllers\webotclient\web ot.cpp(194) : error C2352: 'myWebot::getMyArClientBase' : illegal call of non-static member function
    c:\my_Proj\webotclient\controllers\webotclient\web ot.h(33) : see declaration of 'myWebot::getMyArClientBase'
    c:\my_Proj\webotclient\controllers\webotclient\web ot.cpp(204) : error C2352: 'myWebot::getMyArClientBase' : illegal call of non-static member function
    c:\my_Proj\webotclient\controllers\webotclient\web ot.h(33) : see declaration of 'myWebot::getMyArClientBase'
    c:\my_Proj\webotclient\controllers\webotclient\web ot.cpp(204) : error C2227: left of '->getRunningWithLock' must point to class/struct/union.

    can anybody help me how to overcome this problem and to build the solution.
    Attached Files Attached Files
    Last edited by rmsv_sen; 03-02-2008 at 07:45 PM. Reason: to introduce the main function

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    myWebotRun is static and getMyArClientBase is not. Did you do that on purpose? Do you know what static does? If yes, why are you using it that way here? What are you trying to accomplish?

    The error is because a static function cannot just call a non-static function. The non-static member function must be called from an instance of the object, but a static function doesn't have an instance that its called from.

  3. #3
    Registered User
    Join Date
    Mar 2008
    Posts
    2
    Dear David,

    mywebotrun is a static function, i know it. but it is the template/macro given by the webot environment. but getmyClientbase is a nonstatic function. my webotrun is also a nonreturn function. my purpose is to get the Clientbase of the robot in each and every run of the webot environment so that the webot can give the graphical display of the robot movement.

    If i make the getmyClientbase as a static function, my clientbase will not function. if i make the mywebotrun as a nonstatic function my webot environment will not work.

    Can you suggest me any other method to tackle such a kind of problem.

  4. #4
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,424
    Your static function myWebotRun I suppose should get in some way the pointer to this

    1. It can get it as a parameter void* context and then cast to appropriate type
    2. Or you can make the class singleton - and store this pointer in some static member

    I do not know what is more appropriate for your environment
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Linking errors with static var
    By Elysia in forum C++ Programming
    Replies: 8
    Last Post: 10-27-2007, 05:24 PM
  3. SSH Hacker Activity!! AAHHH!!
    By Kleid-0 in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 03-06-2005, 02:53 PM
  4. opengl program as win API menu item
    By SAMSAM in forum Game Programming
    Replies: 1
    Last Post: 03-03-2003, 06:48 PM
  5. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21