• Advertisement
Sign in to follow this  

problems declaring const std::string - SOLVED

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