* "Seb" <as**********@somewhere.com> schriebt:
I am trying to initialize a const static object data member in a header
file? The following code errs.
class Object
{
public:
virtual const char* ToString() { return "Object"; }
virtual DataType GetType() { return DataType( "Object" ); }
protected:
const static DataType _dataType( "Object");
};
I don't want to have to create a .cpp file for many of my utility headers.
Any help would be greatly appreciated.
Method 1:
class Gurgle
{
public:
static DataType const moo()
{
static DataType const theDataType( "Gurgle" );
return theDataType;
}
};
Method 2:
template< class ADummy_ >
class Gurgle_
{
public:
static DataType const moo;
};
template< class ADummy_ >
DataType const Gurgle_::moo( "Gurgle" );
struct Dummy_ {};
typedef Gurgle_<Dummy_> Gurgle;
--
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?