Global classes and a typedef question!

This is a discussion on Global classes and a typedef question! within the C++ Programming forums, part of the General Programming Boards category; Hello. I've made a class called CWorld. It has members like 'hge' and 'loadedMap'. The class looks like this: Code: ...

  1. #1
    Hail to the king, baby. Akkernight's Avatar
    Join Date
    Oct 2008
    Location
    Faroe Islands
    Posts
    717

    Global classes and a typedef question!

    Hello.

    I've made a class called CWorld. It has members like 'hge' and 'loadedMap'.
    The class looks like this:
    Code:
    class CWorld {
    
    public:
    
    	HGE* hge;	// Leaving this as a pointer as I like using '->' for hge stuff
    	hgePolygonMap* loadedMap;	// Same as above and other reasons
    
    	CWorld()  { hge = hgeCreate(HGE_VERSION); loadedMap = new hgePolygonMap(hgeVector(SCREEN_WIDTH, SCREEN_HEIGHT), true); }
    
    };
    Now, why doesn't it work to do
    Code:
    if(CWorld::hge->System_Initiate())
    Code:
    CWorld::hge->System_Start();
    And so on?

    Also, is it possible to do
    Code:
    typedef CWorld::hge hge;
    I get some errors for that...

    Thanks in advance!
    Currently research OpenGL

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,623
    hge is a non-static member variable so you need a CWorld object to access it.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Hail to the king, baby. Akkernight's Avatar
    Join Date
    Oct 2008
    Location
    Faroe Islands
    Posts
    717
    Not used to working with static members...
    Code:
    class CWorld {
    
    public:
    
    	static HGE* hge;	// Leaving this as a pointer as I like using '->' for hge stuff
    	static hgePolygonMap* loadedMap;	// Same as above and other reasons
    
    	CWorld()  { hge = hgeCreate(HGE_VERSION); loadedMap = new hgePolygonMap(hgeVector(SCREEN_WIDTH, SCREEN_HEIGHT), true); }
    
    };
    gives me this error
    Code:
    error LNK2001: unresolved external symbol "public: static class HGE * CWorld::hge" (?hge@CWorld@@2PAVHGE@@A)
    Currently research OpenGL

  4. #4
    Hail to the king, baby. Akkernight's Avatar
    Join Date
    Oct 2008
    Location
    Faroe Islands
    Posts
    717
    Nevermind!

    Moved hge elsewhere, but thanks for reply tho!
    Currently research OpenGL

Popular pages Recent additions subscribe to a feed

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