• Advertisement
Sign in to follow this  

Which is better form?

This topic is 4618 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
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. **

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement