T
Tagore
hi,
consider following class:
class A
{
int i;
public:
A(int k)
{ i=k;}
};
Now I can create an object of class in 2 ways:
A a; //first method
A a(10); //second method
In first method, a default constructor implicitly defined is called.
but value of i remains garbage. and instance is not consistent.
How can I enforce that this default constructor is not called and
first method generates an error.
SECOND QUERY
I have seen that I can also define constructor A as
A(int k):i(k)
{ }
How this method differs from one define earlier?
consider following class:
class A
{
int i;
public:
A(int k)
{ i=k;}
};
Now I can create an object of class in 2 ways:
A a; //first method
A a(10); //second method
In first method, a default constructor implicitly defined is called.
but value of i remains garbage. and instance is not consistent.
How can I enforce that this default constructor is not called and
first method generates an error.
SECOND QUERY
I have seen that I can also define constructor A as
A(int k):i(k)
{ }
How this method differs from one define earlier?