Possible Duplicate:
Initializing in constructors, best practice?
I'm new to C++.
Suppose we have this class definition:
Class MyClass {
int a;
int b;
//....
}
I would like to know which is the difference between the two class contructors:
public:
MyClass(int a, int b) : a(a), b(b) {}
and (i would say Java-style):
MyClass(int a, int b) {
this->a = a;
this->b = b;
}
I suppose the first is better in C++; right? why?