PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : [C++] only static const integral data members can be initialized within a class?


Nasenbaer
2008-12-01, 09:16:16
Hi,
ich komm bei o.g. Fehler nicht weiter. Die MSN library meint, dass nur integrale Datentypen, die auch als static const definiert sind, initialisiert werden dürfen.
Das hab ich aber:


class MathRT
{
private:
static const float RADMUL = 3.1415926535f / 180.0f;
static const float DEGMUL = 180.0f / 3.1415926535f;
MathRT() {};
public:
static const float EPSILON = 0.0000001f;
static const float PI = 3.1415926535f;
};

Bei allen 4 Variablen bekomme ich diesen Fehler. Der GCC hatte nicht gemeckert aber Visual C++ 2005 stört sich hieran. :/

Marscel
2008-12-01, 09:48:01
http://www.research.att.com/~bs/bs_faq2.html#in-class

Nasenbaer
2008-12-01, 09:51:29
Achso ganzzahlig. :/ Hmmmpf und wie definier ich mir dann sonst solche konstanten?! ich hätte die schon gerne in einer Klasse.

MuLuNGuS
2008-12-01, 09:59:41
hmm, so!?


class MathRT
{
private:
static const float RADMUL;
static const float DEGMUL;
MathRT() {};

public:
static const float EPSILON;
static const float PI;



};

const float MathRT::RADMUL = 3.1415926535f / 180.0f;
const float MathRT::DEGMUL = 180.0f / 3.1415926535f;
const float MathRT::EPSILON = 0.0000001f;
const float MathRT::PI = 3.1415926535f;

Nasenbaer
2008-12-01, 20:58:45
hmm, so!?


class MathRT
{
private:
static const float RADMUL;
static const float DEGMUL;
MathRT() {};

public:
static const float EPSILON;
static const float PI;



};

const float MathRT::RADMUL = 3.1415926535f / 180.0f;
const float MathRT::DEGMUL = 180.0f / 3.1415926535f;
const float MathRT::EPSILON = 0.0000001f;
const float MathRT::PI = 3.1415926535f;


Jo danke so funktioniert es. Versteh nur nicht warum man das nicht gleich in der Delcaration machen darf. Lustiger Standard... ^^