Void return type and no return type

Jun 4, 2010 at 1:16pm


Constructor and Destructor have "no return" type not even "void".
What is difference between void return type and no return type in C++
because void also returns nothing ??
I found something written like : "For Void return value function returns nothing but still have the option to make it something else"....... Pls someone explain it what this statement means.... Thanks
Jun 4, 2010 at 4:05pm
I have no idea, I think the statement is not clear enough.

Anyway, functions with return type void basically mean they don't return a value. Constructors and Destructors are a bit different than functions. Constructors and Destructors can't return values, therefore, it would be unnecessary to write "void" everytime.
Jun 4, 2010 at 4:52pm
Constructors and Destructors are unique in not specifying a return type.

In a ctor or dtor, you _cannot_ return something, even if you would like to. All other functions you _could_ return something if you chose to do so.

If you really need to return something when constructing an object, you can use the named constructor idiom.
Jun 5, 2010 at 8:29am
Thank you forl the replies they have been very useful :)
Topic archived. No new replies allowed.