Advertisement Jump to content
Sign in to follow this  
garyfletcher

problems declaring const std::string - SOLVED

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

Morning. I'm declaring a constant string (to remove #DEFINE from program) like: const std::string CURSKEY = "CURSKEY"; and I'm getting the following complier errors: SiSECursor.h:7: error: ISO C++ forbids initialization of member `CURSKEY' SiSECursor.h:7: error: making `CURSKEY' static SiSECursor.h:7: error: invalid in-class initialization of static data member of non-integral type `std::string' WHY? I thought this was the standard C++ method of doing this. Any suggestions, hints?

Share this post


Link to post
Share on other sites
Advertisement
It looks as if "CURSKEY" is a constant member of a class.
In this case you cannot initialise the member inside the header file (this only
works for integral types):

// header
class YourClass
{
public:
// ...
static const std::string CURSKEY;
};

// cpp file
const std::string YourClass::CURSKEY = "CURSKEY";

// ...



HTH,
Pat

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!