Advantages of Constructor over Assignment operator

Can any one let me know on what is the advantage of default constructor over assingment operator.

take an example.

class A
{
int a,b;
a=0;
b=0;
};
Class A
{
int a,b;
public:
A()
{
a=0;
b=0;
};

what is the advantage of second over first?
The second is valid C++ code.

The first will not compile.
Disch thanks for the reply!

what if i change to
class A
{
int a=0;
int b=0;
};
I know the answer the second wont compile either! Thanks!
You simply can't make an in-class definition this will not obey the c++ linker rules.

C++ requires that every object has a unique definition. That rule would be broken if C++ allowed in-class definition of entities that needed to be stored in memory as objects.

So you can initialize those members in constructors only, unless it is a static const of integral or enumeration type.
Topic archived. No new replies allowed.