On Aug 23, 8:23 pm, herman <Herman.Schu...@gmail.com> wrote:
Hi,
I have a static class attribute in my class:
class A
{
public:
static B aB;
}
How can I allocate this static class attribute?
aB is a data member, not a pointer. You shouldnot call "new" for
allocating (as you did below)
Simply saying
B A::aB;
will work, provided the definition of B is in scope, and constructor
B::B() is callable.
I think I need to do this
A::aB = ??? ;
If I do this:
A::aB = new B(); // where/when will aB be deleted if I allocate it on
the heap?
you can't do this, since aB is not a pointer
If I dont do anything, I have this linker error:
A.cpp:229: undefined reference to `A::aB'
Finally, lookup "static initialization order fiesco" :http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.12
-N