I've seen c++ class constructors initialize members in two different ways, but with the same effect. Suppose we have a simple class:
class myClass
{
public:
myclass();//default constructor
private:
int a;
int b;
bool c;
};
Case 1:
myClass::myClass()
/* Default constructor */
{
a=5;
b=10;
c=true;
//do more here
}
Case 2:
myClass::myClass()
/* Default constructor */
:a(5),
b(10),
c(true)
{
//do more in here
}
What is the difference between the two after it compiles? Even if there is no difference, is there a "preferred" way of doing it?