contemplating constructor calling

Started by
9 comments, last by sab3156 21 years, 2 months ago
quote:Original post by sab3156
if i instanciate the object and call that constructor like this:

Wheel bike_wheel;......bike_wheel(5.0, 9.0);  


is the default constructor ever called? if so, what if i do it like this:

Wheel bike_wheel(5.0, 9.0);  


is there a difference?

Wheel bike_wheel is, in a sense, merely shorthand for Wheel bike_wheel = Wheel(); - that is, it creates a Wheel with the value returned by the default constructor.

bike_wheel(5.0, 9.0) does nothing - or at least, it does not call a constructor, default or otherwise. To explicitly invoke the constructor, you write Wheel(5.0, 9.0); this returns an object generated by this constructor. On its own (without being assigned to a variable), it will, of course, do nothing very useful.

This topic is closed to new replies.

Advertisement