Get address of variable from pointer

This is a discussion on Get address of variable from pointer within the C++ Programming forums, part of the General Programming Boards category; Hello all, I am working on some code that utilizes OpenSceneGraph functions and am having problems with pointers. The function ...

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

    Get address of variable from pointer

    Hello all,

    I am working on some code that utilizes OpenSceneGraph functions and am having problems with pointers. The function I want to use is of the form
    Code:
     writeNodeFile (const osg::Node &node, const std::string &filename)
    I am trying to get a selected node (which is a pointer), find out how many children that node has, and then write each child to a file. My problem is that I cannot figure out how to make my osg::Node *child into const osg::Node& child for use in the function.

    Code:
    osg::Node *node = dynamic_cast<osg::Node *>(editor->getSelected()); //get selected node from scenegraph
    			for (int i = 0; i< ((osg::Group*)node)->getNumChildren(); i++){  //get number of children of selected node (children are also nodes)
    				//write children to .osg file
    				osg::Node *child = ((osg::Group*)node)->getChild(i);  //returns osg::Node*	
    				std::string childname = i + ".osg";  //filename for child
    				osgDB::writeNodeFile(child , childname);  //save child <-----ERROR HERE
                          }
    I get the error "cannot convert from 'osg::Node*' to 'osg::Node&'".

    Does anyone have any suggestions?

    Thanks,
    JackR

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Try this.
    Code:
    				osg::Node *child = ((osg::Group*)node)->getChild(i);  //returns osg::Node*	
    				std::string childname = i + ".osg";  //filename for child
    				osgDB::writeNodeFile(*child , childname);  //save child <-----ERROR HERE

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    27
    Thanks for the suggestion swoopy.

    I tried adding the * and got over 3000 unresolved external errors. I am compiling using Microsoft Visual C++ .NET and added the path for the new osgDB library to Tools->Options->Projects->Library files and linked osgDB.lib the project as an additional dependency.

    What is strange is that the unresolved external symbol errors pop up for functions and classes from OSG and GTK that were running fine before.

    What does adding the * actually do?
    Last edited by JackR; 06-15-2007 at 09:53 AM.

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    7,340
    It sounds like when the * fixes the compile error, and your code is able to finish compiling successfully. The second step after compilation is linking. That is failing, and it has nothing to do with the error you fixed with the *.

    >> What is strange is that the unresolved external symbol errors pop up for functions and classes from OSG and GTK that were running fine before.
    Do you mean the entire application was compiling and linking before, or do you mean that you didn't see linker errors before when you had the compiling errors?

    BTW, the * dereferences the pointer to access the object it points to. The function takes a reference to a Node, but child is a pointer. The * converts pointer to the object so a reference to it can be sent to the function.

  5. #5
    Registered User
    Join Date
    Sep 2006
    Posts
    27
    Ah. I see now.

    I will work on fixing my linking errors, then.

    Thanks for the help!
    JackR

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to set pointer for environment variable
    By spiky1 in forum C++ Programming
    Replies: 7
    Last Post: 08-18-2006, 05:19 PM
  2. How did you master pointers?
    By Afrinux in forum C Programming
    Replies: 15
    Last Post: 01-17-2006, 07:23 PM
  3. Could somebody please help me with this C program
    By brett73 in forum C Programming
    Replies: 6
    Last Post: 11-25-2004, 01:19 AM
  4. towers of hanoi problem
    By aik_21 in forum C Programming
    Replies: 1
    Last Post: 10-02-2004, 01:34 PM
  5. Pointer address
    By cheeves in forum C Programming
    Replies: 7
    Last Post: 10-30-2003, 07:26 PM

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