Jump to content
  • Advertisement
Sign in to follow this  
Unconquerable

class question

This topic is 4423 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. I have a class declared as an extern, and when i try to use it in my code , i get : [Linker error] undefined reference to `Logger' . Any help would be appreciated. Thanks.

Share this post


Link to post
Share on other sites
Advertisement
There's no such thing as an extern class. Assuming that you meant that have declared a global variable of a class type as extern, then in one source file you still need to define the variable. Ex:

extern Foo foo; // in the header

Foo foo; // in one source file at namespace scope (not inside a class or function)

Share this post


Link to post
Share on other sites
Quote:
Original post by Unconquerable
Yeah thats what i ment.


then post the code where you extern it as well as the code where you define it.

-me

Share this post


Link to post
Share on other sites

class Log
{
private:
ofstream outFile;
public:
Log( string fileName )
{
outFile.open( fileName.c_str() );
}


void LogInt ( int number)
{
outFile << number;
}
~Log()
{
outFile.close();
}
};



extern Log Logger;

....

Logger.LogInt(iShiptwo_x);




Share this post


Link to post
Share on other sites
It looks like you have a constructor that accepts a file name as a string, but you don't appear to supply it a filename, and it doesn't have a default.

EDIT: Take everything I say with a grain of salt, I am still in C++ learning phase as well.

Share this post


Link to post
Share on other sites
Quote:
Original post by -JetSirus-
It looks like you have a constructor that accepts a file name as a string, but you don't appear to supply it a filename, and it doesn't have a default.

EDIT: Take everything I say with a grain of salt, I am still in C++ learning phase as well.


I fixed that, still the same error though.

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!