Jump to content
  • Advertisement
Sign in to follow this  
philipptr

(c++) Forward declaration (SOLVED)

This topic is 4709 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

(c++) I have 4 files, 2 headers and 2 cpp files, and a class which is written in bige.cpp and a forward declaration in bige.h The list below shows all important code. My problem is that the class was in bige.h before and since i've put it in bige.cpp it doesnt work anymore.. header.h bool bige_NormalMaskBlit (int x, int y, bige_texture &texture, float depth, unsigned int zoom); main.cpp #include "bige.h" bige_texture Cursor; bige.h class bige_texture; bige.cpp #include "header.h" #include "bige.h" class bige_texture { static std::map<GLuint, int> usages; ... } Error messages: aggregate `bige_texture Cursor' has incomplete type and cannot be defined elements of array `bige_texture GuiElements[10]' have incomplete type storage size of `GuiElements' isn't known and so on. does someone know what i have to have inside the bige.h to make it work? [Edited by - philipptr on December 30, 2005 3:29:17 AM]

Share this post


Link to post
Share on other sites
Advertisement
you have to declare the class in your header before you can use them. The only exception to this rule are pointers and references.

class bige_texture
{
static std::map<GLuint, int> usages;

...

};

should go into bige.h


Share this post


Link to post
Share on other sites
That's because it's a static variable that needs to be defines somewhere.
Put the following line into bige.cpp:

// this DEFINES the static variable, while the header only DECLARES it as being static
std::map<GLuint, int> bige_texture::usages;



The reason for this is that "usages" is not part of the class instance and therefore not allocated along with the non-static members of the class.

The linker has to allocate some space for the variable nonetheless since all class instances use it. You will have to tell the compiler in which compilation unit (cpp-file) to allocate space for it.

HTH,
Pat.

Share this post


Link to post
Share on other sites
thanks, now my game compiles for the first time since quite some time, and quits even before running the first statement inside the main(), guess I need to work on the constructor.. thanks very much really helped

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!