Which is better form?

Started by
2 comments, last by pragma Fury 18 years, 10 months ago
I have a class with one member that should be set in the constructor. If no value is given, a meaningful default value is assigned (in other words, the default value makes sense). Is it better to make a default constructor + second constructor with one parameter, or only a constructor with one parameter which has a default vlaue? If I'm not clear, tell me. :P
Advertisement
they are in effect the same thing, but the benefit of having only one with adefautly over two seperate ctors is less redundant code/maintenance.

** always check to see if the keyword explicit is useful in order to prevent implicit casts. **
thanks :)
FYI: MSVC will generate a "warning C4520: '[ClassName]' : multiple default constructors specified" warning if you try this.. And I think Borland C Builder will error. Other compilers may do different things.

class Foo {public:  Foo(){};  Foo(int n=0){}};


Edit: Sorry, I realized after the fact that I wasn't directly addressing the question. "Anonymous" is right though... and I'm sure I've had BCB complain about it.

This topic is closed to new replies.

Advertisement