-
quick syntax question
hi,
I have this piece of code from a course I'm studying, but I can't make out all the details. Could someone please explain some of the syntax to me?
Code:
class A {
public:
A();
A(int i);
void setVarA (int i);
int getVarA ();
private:
int varA;
};
class B : public A {
public:
B();
B(int i);
B(int vara, int varb);
void setVarB (int i);
int getVarB ();
private:
int varB;
};
A::A():varA(0) {}
A::A(int i):varA(i) {}
B::B():A(),varB(0) {}
B::B(int i):A(),varB(i) {}
B(int vara, int varb):A(vara), varB(varb){}
I know about classes, about namespaces and inheritance. So I get the decleration of the classes A & B, with their constructors, methods etc.
What I don't get is the last bit of code:
Code:
A::A():varA(0) {}
A::A(int i):varA(i) {}
B::B():A(),varB(0) {}
B::B(int i):A(),varB(i) {}
B(int vara, int varb):A(vara), varB(varb){}
I know A::A() calls A's constructor, but what does the added :varA(0) do? is it a way to define the constructors outside the class? If so, can it be done to other functions as well?
I'd very much appreciate if someone could put a name to this technique so I can do some reading on it.
thx in advance
-
-