class complex
{
int real;
int imag;
public:
complex(){}//why default constructor is always needed
complex(int a,int b){real = a;imag = b;}// why can't we define only this constructor
~complex(){}
};
smrati.katiyar
0
Newbie Poster
Recommended Answers
Jump to PostIf you don't define any constructors, the compiler will generate a default constructor for you (or make it appear as if one was generated). However, the instant you define an explicit constructor, that default constructor is not longer created.
As for why your class needs an explicit default constructor, …
All 3 Replies
Narue
5,707
Bad Cop
Team Colleague
smrati.katiyar
0
Newbie Poster
Narue
5,707
Bad Cop
Team Colleague
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.