extern class beast.GreenSlime;
whats the correct way to declare this in a header? using Dev C++, thanks.
Header Error
my prog is popping up a 'parser error' with the following line:
I'm not surprised. Are you trying to forward declare a class? A variable? A class contained within another class? Something else?
Σnigma
Σnigma
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'.
try:
extern beast GreenSlime;
in your header file withbeast 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.
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:
[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;}
As well as a declaration you need a definition in exactly one source file:
beast GreenSlime;
Σnigma
beast GreenSlime;
Σnigma
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
Quote:Original post by EnigmaQuote: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?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement