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

Recommended Posts

my prog is popping up a 'parser error' with the following line:
extern class beast.GreenSlime;
whats the correct way to declare this in a header? using Dev C++, thanks.

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

Σnigma

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 on other sites
try:
extern beast GreenSlime;
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 on other sites
Okay I did so and it works. I get a different error later in the compile though:

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 on other sites
As well as a declaration you need a definition in exactly one source file:

beast GreenSlime;

Σnigma

Share on other sites
Ahh... thanks, everything works fine now.

Share on other sites
Quote:
 Original post by Servant of the Lordif(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 on other sites
Quote:
Original post by Enigma
Quote:
 Original post by Servant of the Lordif(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 on other sites

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

Create an account

Register a new account

• Forum Statistics

• Total Topics
628760
• Total Posts
2984544

• 12
• 25
• 12
• 10
• 17