Let us consider the following classes
class test1
{
private:
int a;
int b;
public:
test1():a(0),b(0){}
};
class test2
{
private:
int a;
int b;
public:
test2()
{
a=0;
b=0;
}
};
Now, I know that test1()
constructor is the right way to initialize the data members of a class
, because in test2()
we are performing assignment and not initialization. My questions are:
- What might go wrong if we perform assignment instead of initialization?
- Doesn't the compiler internally perform assignment in case of
test1()
constructor? If not, then how are these initialized?