Object Oriented issue

So, I have a C++ object named Airplane.
It has a pointer to a NodePath with the airplane model and after working on some game logic and inputs it adjusts the position and rotation of the NodePath accordingly.

Right now I am only creating one instance of Airplane and I am passing an externally created NodePath as a parameter of its constructor.
This method is working very well for just one airplane.

I want to be able to create, have, and destroy multiple of these objects during runtime. I would like each one of the instances to create its own nodepath and load its own model upon creation. It might even be better to just load the airplane model once and have every Instance of airplane make a copy of the preloaded model for its NodePath rather than loading it from file every time.

Anyway, I figured that the Airplane class needs its own pointer to the WindowFramework object in order to load models so I made a static member pointer of WindowFramework called Win and I created the following static member function:

void Airplane::OnGameStart(WindowFramework* winsom)
{
Win = winsom;
}

Trouble is this gives me a linker error in Visual C++.

1>Airplane.obj : error LNK2001: unresolved external symbol “public: static class WindowFramework * Airplane::Win” (?Win@Airplane@@2PAVWindowFramework@@A)

I assume this means I can’t have a static member pointer to a WindowFramework.

I am still fairly noobish in C++ and very noobish in Panda so I wouldn’t be surprised if I am taking a very wrong approach to this whole situation.

thanks in advance,

hi,

first of all when you say

do you mean you did this ?

NodePath* pMyAirplane

if yes then that would be wrong. NodePaths are handles to actual nodes in the panda scenegraph.
They are not pointers. If you didn’t know that I suggest you start with something simpler to understand
how the Panda SDK is supposed to work in C++. Especially if you are new to C++.

your airplane class could look something like this :

class cMyAirplane
{
public:
       cMyAirplane(const char* pFilename);
       ~cMyAirplane();

        void AddToWorld();
        void RemoveFromWorld();

        void Update();
        void HandleInput( /*some sort of input structure */ );
private:
        NodePath  mMyAirplaneModelNode;
};

and the implementation could look like this :

cMyAirplane::cMyAirplane(const char* pFilename)
{
    mMyAirplaneModelNode = gMyFramework.LoadModel(gMyFramework.get_models(), pFilename);
}

(the loading of the model might be a bit wrong (I am sitting at my office desk and haven’t got access to panda right now so I am kind of coding from what I remember)

Panda will load the model the first time arond and for each subsequent load it will try and return and instance of the existing model resource (hence the concept of “handles” ).

about the static member of your class to WindowFramework… that shouldn’t be necessary at all to be honest. But for the sake of it have you included the header of the WindowFramework ?
As I say you shouldn’t need to do this anyway.

hope I could help you a bit.

Chrys

Unlike nonstatic members, static class members have to declared in your .cxx file. Like this:

WindowFramework * Airplane::Win;

Put this near the top of your .cxx file, after you have made all of the #includes, and before you declare any methods.

David