Jump to content
  • Advertisement
Sign in to follow this  
OpenGL_Guru

Enumerated Types in Classes --

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

i havent dealt with enum types much in a regular program as i havent really seen much need with them. however i thought i would try to use them in classes and see how they were. i have defined part of the class as such:

class myClass
{
 public:
    virtual ~myClass(void);

    enum colorMode
     {
       blue,
       red,
       green,
       white
     };

     myClass(const char *file, colorMode = white);

  .........
............

};



so i am trying to get my main program working calling the class but get errors..
 int main()
{
 myClass *foobar;

 foobar = new myClass("file.txt", myClass::blue);

return 0;

} 


however with this i get an unresolved external error... main.obj : error LNK2001: unresolved external symbol "public: __thiscall myClass::myClass(char const *,enum myClass::colorMode)" (??0myClass@@QAE@PBDW4colorMode@0@@Z) Debug/enum_test.exe : fatal error LNK1120: 1 unresolved externals Error executing link.exe. am i trying to assign something to an enum type from name not allowed? anyway thanks for your help on this :) [Edited by - OpenGL_Guru on June 16, 2005 8:54:40 AM]

Share this post


Link to post
Share on other sites
Advertisement
It's an unresolved external, meaning the linker cannot find the definition for the constructor. Make sure you've actually defined it somewhere.
myClass foobar;
foobar("file.txt", myClass::blue);

This doesn't call the constructor you listed anyway, it default constructs a myClass object and then tries to call operator() on it. Typo in your post?
const char *file

This is spelt std::string file [wink]

Enigma

Share this post


Link to post
Share on other sites
Don't you actually mean

int main()
{
myClass foobar("file.txt", myClass::blue);
return 0;
}


?

I don't get any errors when compiling your example.

Your error message specifies the decorated symbol name as being something different from your actual symbol name, though. Undecorating that string gives:
"public: __thiscall myClass::myClass(char const *,enum myClass::FileMode)"
which is what it is looking for. Perhaps all you need to do is a "Clean" and "Rebuild All".

Share this post


Link to post
Share on other sites
actually i am sorry, i forgot to add what i already had.. its early in the morning :) i changed the code to what i actually have down here...which is a pointer then i use a new to instantiate the class.. :-)

Share this post


Link to post
Share on other sites
Quote:
Original post by Enigma
const char *file

This is spelt std::string file [wink]



I know it's off topic, but personally I don't see the point in instantiating a std::string just for a filename. If you're not doing any string operations on it, or storing it somewhere, then I don't think there's any point. Sure, if you're going to store the filename inside the object, then use a std::string for that, but I'd still have a const char* for the filename parameter.

Someone could pass a null pointer, but personally, If I were using std::string, I'd have an assert, or some other check that the string wasn't empty, so checking for a null pointer isn't really any different.

You could argue that someone could cast something to a const char* that isn't a string, but if they do that then they deserve what they get, and besides, using that logic, you could say that you shouldn't use std::string, in case someone casts c_str() to a char* and deletes it.


To me, the only reason I can see to use std::string there, is "char* is evil, it is always evil, there are absolutely no exceptions to this rule, use std::string".

Share this post


Link to post
Share on other sites
The error you're seeing does not exist [headshake]. At least, not like this.

If you create a new console program with just the code you're posting (and an implementation for the destructor and constructor), you will not get the error.

By editing your program before posting it here, you're taking away the cause of the error you're experiencing. One thing that can be of critical importance here is what include files you include in the file that has the implementation of "myClass" and the one that has "main" in it. Try renaming "fileMode" to "xFileMode" for instance and see whether that makes a difference.

That said... you did actually implement the constructor, didn't you? It's not in your code. If it's in a separate CPP file, make sure that is actually a part of your project.

[Edited by - Kippesoep on June 16, 2005 2:49:03 PM]

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!