space_otter
10th March 2010, 06:13
This is probably a noob question, but...
When I create a static class member of an object type, for example:
class A {
static const A fixed = A();
// should really be immutable, but const not necessary
};
It produces an error "invalid in-class initialization of static data member of non-integral type" so i leave it as:
class A {
static A mFoo;
// should really be immutable, but const not necessary
};
hoping that A will be defined, but apparently it's not. If I leave it like this and try to define it in a function it complains "undefined reference to `A::mFoo'". Examples on the subject use integral data types so it works. I want it to be a fixed object. So how am I supposed to define it?? If I use a pointer and allocate memory the situation doesn't change.
When I create a static class member of an object type, for example:
class A {
static const A fixed = A();
// should really be immutable, but const not necessary
};
It produces an error "invalid in-class initialization of static data member of non-integral type" so i leave it as:
class A {
static A mFoo;
// should really be immutable, but const not necessary
};
hoping that A will be defined, but apparently it's not. If I leave it like this and try to define it in a function it complains "undefined reference to `A::mFoo'". Examples on the subject use integral data types so it works. I want it to be a fixed object. So how am I supposed to define it?? If I use a pointer and allocate memory the situation doesn't change.