Regarding Constructors and Functions

Hi
This is sunil.
I have a doubt regarding function with return types.
Iff any return type is not mentioned it defaults return int.
If the same we consider for constructors in C++, does it return any value.
Is there any difference between the functions defined without any return type(without void also) and the costructors defined in C++ apart from the calls made to them.


Comments

  • Yes, if an ordinary function has no type specified in C++ it automatically defaults to returing an integer type. That rule applies to all functions including methods of a class. It DOESN'T apply to constructors of a class. The difference is that a constructor is an override to the default constructor that would be created for the class if you didn't write one specifically for it. It is well explained in the book "Thinking in C++" by Bruse Eckel. This book, volumes 1 & 2, are both available at www.mindview.net for free download. It explains a lot of things very well, but may seem too advanced at first. My advice is get it, read it over and reread parts that apply to every question you find not answered by my feeble attempt and you'll probably have a better grasp of it than I.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion