I saw the following code some time ago and nobody could answer me what was, neither knew about it.
I am using Visual Studio 2010, as C++, in a file saved as cpp (at a project of win32 cmd program), then i declare the following:
class People {
private:
string name;
short age;
public:
People (string name,short age)
: name(name),
age(age)
{
//
}
inline string getName(void) {return name;}
};
class Professor : public People {
private:
int salary;
int nAlunos;
public:
Professor(string name, short age, int salary, int nAlunos)
: People(name,age),
salary(salary),
nAlunos(nAlunos)
{
//
}
};
Why does this assignment of the values work?
Notice that I don’t write explicitly: name = newName, the stuff works on its own.
I also tried at wxDev-CPP and worked.
You mean the initialization lists? That’s where you can initialize parent classes and member variables as part of your constructor.
http://www.cprogramming.com/tutorial/initialization-lists-c++.html