Probably because the are not explicitely called in your code, so what good would it do to return a value -- nobody is going to be listening.
The constructor is only called when you instantiate an object. There is no way to catch the return value of the constructor.
// This doesn't make sense!!
int x = CMyClass SomeObject;
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
>Can anyone explain me in simple language and better if with an
>example why constructor don't have return types
Here's an idea. Show us how it could be done without breaking all kinds of existing code, and you'll answer your own question.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
...can u explain me this....
Nope. I don't know what taking the address of a function has to do with returning a value. constructors don't return values because c++ standards and language say they don't. ;)
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
Another option -- don't put any code in the constructor that might cause it to fail. M$ MFC is good at that -- first instantiate the object and then call its Create() method. The constructor only initializes class data to some default value (normally 0). Then the Create() method initializes all the rest and either returns a value or throws and exception.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343