Jump to content
  • Advertisement
Sign in to follow this  
Servant of the Lord

Header Error

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

Advertisement
I'm not surprised. Are you trying to forward declare a class? A variable? A class contained within another class? Something else?

Σnigma

Share this post


Link to post
Share on other sites
I have my class, beast, and my object, GreenSlime, and need to declare(?) them in a header file. It needs to be able to be viewed by multiple files in the same project so I am declaring it in 'main.h'.

Share this post


Link to post
Share on other sites
try:
extern beast GreenSlime;
in your header file with
beast GreenSlime;
in your cpp file. The "extern beast GreenSlime;" is the declaration of your variable (GreenSlime) and that declaration will be visible to all of the files that include the header file. The "beast GreenSlime;" in your cpp file should only be compiled once. The linking step of building will take care of making sure all of your files are using the same object.

Share this post


Link to post
Share on other sites
Okay I did so and it works. I get a different error later in the compile though:

[Linker error]undefined reference to 'GreenSlime'

It was repeated several times to; and I think it was refering to the following code:

if(enemy = 1)
{
Ehp = GreenSlime.Hp;
Edmg = GreenSlime.Dmg;
Edef = GreenSlime.Def;
Eexp = GreenSlime.Exp;
Ecoin = GreenSlime.Coin;
Ename = GreenSlime.Name;
}

Share this post


Link to post
Share on other sites
As well as a declaration you need a definition in exactly one source file:

beast GreenSlime;

Σnigma

Share this post


Link to post
Share on other sites
Quote:
Original post by Servant of the Lord
if(enemy = 1)

Just spotted that. I assume you meant if (enemy == 1). Assuming this is an error in your source and not a forum transcription error your compiler should have warned you about an assignment in a conditional. Listen to it. If it's not issuing a warning then find the compiler option that will make it.

Σnigma

Share this post


Link to post
Share on other sites
Quote:
Original post by Enigma
Quote:
Original post by Servant of the Lord
if(enemy = 1)

Just spotted that. I assume you meant if (enemy == 1). Assuming this is an error in your source and not a forum transcription error your compiler should have warned you about an assignment in a conditional. Listen to it. If it's not issuing a warning then find the compiler option that will make it.

Σnigma


Whoops, I do mean '=='. I wonder why my compiler missed that? I wonder how I missed that?

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!