I'd like to have a class that has static members to itself, but I can't figure how to do that. Is that even possible?
I get the error:
only static const integral data members can be initialized within a class
Code:
namespace misc
{
class CData
{
public:
CData( ) { };
CData( int d );
CData& operator = ( const CData& d );
static const CData FIRST = CData( 512 ); //how?
private:
int data;
};
}
As I use FIRST
a lot I would like to statically access it using misc::CData::FIRST
without the need to declare it somewhere in the scope. Is that by any chance possible?
--std=c++11
(or--std=gnu++11
) to your compiler options. – Ben VoigtFIRST
to be a static data member because you access it a lot? And why the restriction against declaring (I'm assuming you meant defining) it elsewhere? – Praetorian