illegal call of non-static member function

This is a discussion on illegal call of non-static member function within the C++ Programming forums, part of the General Programming Boards category; Hello all, I realize that this has been addressed before, but I cannot figure out what to do in my ...

  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    27

    illegal call of non-static member function

    Hello all,

    I realize that this has been addressed before, but I cannot figure out what to do in my situation.

    I am using an osg function to replace one node with another, but my problem is unrelated to osg--I am having problems figuring out how to call a function.

    The relevant code is as follows:
    Code:
    class ToolReplaceNode: public FileSelTool {			//attempt to create .txt file by Catherine Peloquin 5-31-07
    public:
        ToolReplaceNode():FileSelTool("replacenode") {}
        virtual void fileSelected(const char *n) {
    		const std::string name = n;
    		osg::Node *new_node = osgDB::readNodeFile(name);
    		osg::Node *old_node = dynamic_cast<osg::Node *>(editor->getSelected());
    		osg::Group::replaceChild(old_node, new_node);  //<---ERROR HERE
    
    	}
    	virtual Tool* clone() { return new ToolReplaceNode(); }
    };
    At the line osg::Group::replaceChild, I get the error "illegal use of non-static member function".

    I know I am calling the function incorrectly, but how do I call it?

    Thanks,
    JackR

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    what is osg::Group::replaceChild?

    what is this line for?
    Code:
    ToolReplaceNode():FileSelTool("replacenode") {}

  3. #3
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    907
    Apparently osg::Group::replaceChild() can be called only from an instantiated type. It is not a function that can operate independent of object context (i.e. static). So yeah,
    what is osg::Group::replaceChild?
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    27
    Replacechild is defined as
    Code:
    virtual bool 	replaceChild (Node *origChild, Node *newChild)
    in the class osg::Group.

    The line
    Code:
     ToolReplaceNode():FileSelTool("replacenode") {}
    just means that the ToolReplaceNode tool uses a file selection.

  5. #5
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    I think you're looking for
    Code:
    ToolReplaceNode()
    {
        FileSelTool("replacenode") ;
    }

  6. #6
    The larch
    Join Date
    May 2006
    Posts
    3,573
    As replaceChild is a non-static member function, you'll need an instance of the class to call it on.

    However, if it doesn't refer to other non-static members of the class, you can make it static instead.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. Static & Data Member
    By ecoliteracy in forum C++ Programming
    Replies: 1
    Last Post: 04-16-2007, 09:46 PM
  3. Staticly Bound Member Function Pointers
    By Polymorphic OOP in forum C++ Programming
    Replies: 29
    Last Post: 11-28-2002, 01:18 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 06:06 PM
  5. qt help
    By Unregistered in forum Linux Programming
    Replies: 1
    Last Post: 04-20-2002, 10:51 AM

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