T
Tran Tuan Anh
Dear all,
I am new with C++ and very confused with some features.
Really appreciate if you can explain to me some of stuffs below.
I define a class:
class A {
static A* instance = 0;
};
then I have error saying that I cannot initialize a static member
inside the class. Why? As a newbie to C++ I don't see why not?
then I move the initialization outside to A.cpp:
A::instance = 0;
then compiler complains and I have to do the following:
A* A::instance = 0;
Here I also don't see why. For example, if I have an interger:
int i;
then I initialize it by:
i = 0;
that is it. Why the instance var above need the A* type declearation.
Basically, as a newbie to C++ I am very confused with huge syntaxs and
semantics. Really want to learn more.
Many thanks in advance!
Tuan-Anh
I am new with C++ and very confused with some features.
Really appreciate if you can explain to me some of stuffs below.
I define a class:
class A {
static A* instance = 0;
};
then I have error saying that I cannot initialize a static member
inside the class. Why? As a newbie to C++ I don't see why not?
then I move the initialization outside to A.cpp:
A::instance = 0;
then compiler complains and I have to do the following:
A* A::instance = 0;
Here I also don't see why. For example, if I have an interger:
int i;
then I initialize it by:
i = 0;
that is it. Why the instance var above need the A* type declearation.
Basically, as a newbie to C++ I am very confused with huge syntaxs and
semantics. Really want to learn more.
Many thanks in advance!
Tuan-Anh