Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

initialization error

Status
Not open for further replies.

mactonio

Programmer
Joined
Nov 18, 2003
Messages
55
Location
US
hey guys, i'm getting this error from my .h file:
in-class initialization of static data member of non-integral type 'static const string'

here is a part of the code:

#include <string>
..
..
class Class{

static const string mystring = " xox ";
..
..
}

thanks in advance
 
You can't initialize a static member variable like that (except int variables for some strange reason).

In your .cpp file add this to initialize your static variable:
Code:
static const string Class::mystring( " xox " );
 
thanks cpjust, that worked.
 
You could also make it a namespace constant:

The .h
Code:
namespace SomeNameSpace
{
    static const std::string foo = "Bar";
}

Usage:
Code:
std::cout << SomeNameSpace::foo << ...;

/Per

www.perfnurt.se
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top