Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

How can I access a pointer, box in this code, from in a different function, such as this code's update gameloop?

int main()
{
    ScenePrimitive *box = new ScenePrimitive(ScenePrimitive::TYPE_BOX, 1,1,1);
}
int update()
{
 cout box;
}
share|improve this question

closed as off topic by Sam Hocevar, Joe Wreschnig, Byte56, Nicol Bolas, Jonathan Hobbs Sep 9 '12 at 8:08

Questions on Game Development Stack Exchange are expected to relate to game development within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

1  
This is not really game dev related. –  nathan Sep 8 '12 at 11:39
4  
I strongly recommend that you find a decent free C++ book like Thinking in C++. This question demonstrates a lack of fundamental language understanding. –  Lars Viklund Sep 8 '12 at 12:18
1  
-1: Due to lack of research effort. –  Nicol Bolas Sep 8 '12 at 16:45
add comment

1 Answer 1

up vote 1 down vote accepted

You could use a global variable for your sceneprimtive:

ScenePrimitive* gBox;

int main()
{
    gBox = new ScenePrimitive(ScenePrimitive::TYPE_BOX, 1,1,1);

    //..
    delete gBox;
}

int update()
{
    cout gBox;
}

OR take the sceneprimitive as an parameter of your update function:

int update(ScenePrimitive* &Box)
{
    cout Box;
}

int main()
{
    ScenePrimitive* Box = new ScenePrimitive(ScenePrimitive::TYPE_BOX, 1,1,1);

    update(Box);

    //..
    delete Box;
}
share|improve this answer
    
I can't use a parameter since update() is the gameloop. The global works fine however. Thanks –  andrew Sep 8 '12 at 15:13
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.