To quench your thirst for knowledge :)
class Foo
{
int x,y;
public Foo(int _x, int _y) : x(_x), y(_y)
{}
}
And there are a few reasons to prefer this syntax to manually assigning values to members. For one, if you are initializing const or reference members, you'd have to use the above syntax. Two, using the above syntax is more efficient. If you use manual member assignment, there will be two calls (constructor and operator=) for every non-POD member, if you use the above syntax, there will be only one. For eg,
class Foo
{
string x;
public Foo(string y) : x(y) {}
}
There will be only constructor call to string with the above syntax, as the compiler calls string(const string &) for initializing x. If you do
class Foo
{
string x;
public Foo(string y)
{
x = y;
}
}
there will be two, string() and operator=() on string. Regards Senthil _____________________________ My Blog | My Articles | WinMacro