Jump to content
  • Advertisement
Sign in to follow this  
Lonefox1

new class instances?

This topic is 4828 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

Hi guys im just working through "begining openGL game programming" tga loading section and in the init() method i have the following code:

bool CGfxOpenGL::Init()
{	
    *snip*

    m_tga = new CTargaImage;
    m_tgaUncompress = new CTargaImage;
	
    *snip*
}

i get the error: CGfxOpenGL.cpp:26: error: `m_tga' undeclared (first use this function) the code is exactly as in the book, and the same as source code that came on the CD with the book. any ideas why this isnt compiling? :| im using dev CPP

Share this post


Link to post
Share on other sites
Advertisement
If the code is indeed exactly the same as in the book, and it does not compile (linker settings aside, because this is a compiler error and not a linker error), the only logical assumption is that the code in the book is in error.

That said, human error plays a large part in programming and you should quadruple-check to make sure you haven't missed anything.

If you're certain you haven't, then we'd need to see more code or bring in someone who's familiar with that lesson to tell what the problem is.

Cheers,
Twilight Dragon

Share this post


Link to post
Share on other sites
It's probably not compiling because m_tga isn't declared as a member (probably the intention), or a local variable.

Share this post


Link to post
Share on other sites
Just add a declaration for the m_tga variable. I.E. CTargaImage *m_tga; in the private section of the CGfxOpenGL class. Then it should compile fine.

Share this post


Link to post
Share on other sites
... gaahhh! i didnt think about checking the CGfxOpenGL.h, i was just using my template one. human error :P /me slaps self. one question tho in the header CGfxOpenGL.h it has this:

class CTargaImage;

what does this do exactly? does it include the class into the file ? similar to including a .h file?

Share this post


Link to post
Share on other sites
Not quite, LoneFox1.

This is called "forward declaration". What it does is let everything else in the file know that a class called CTargaImage exists, without saying anything else about it. This lets you make references to variables of the CTargaImage type without having to include the whole CTargaImage header.

Cheers,
Twilight Dragon

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!