Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualNarf the Mouse

Posted 22 June 2012 - 01:43 PM

Edit: as a side note, try to avoid plain bool as a flag. Use an enum and specifically state what the thing is or is not. Today there are two choices, but tomorrow you may need a third.

Plus, new Object( MakeBobYourUncle.True ) ; is much less ambiguous than new Object( true ) ;

#1Narf the Mouse

Posted 22 June 2012 - 01:43 PM

Can you remove the default parameter? That would be easiest.

As for delegating constructors, it isn't hard for your constructors to run along the lines:

MyObject::MyObject()
{
   ConstructInternal( NULL, false, true);
}
MyObject::MyObject(Something* ptr )
{
  ConstructInternal( ptr, false, true);
}
MyObject::MyObject(Something* ptr, bool owned )
{
  ConstructInternal( ptr, false, owned);
}
MyObject::MyObject(bool aFlag)
{
  ConstructInternal( NULL, aFlag, true);
}
...
We do this all the time in our game code for exactly the reason you describe in your post.

True it is not as pretty as default parameters, but it does help resolve the problem of implicit conversions.


As the project grows and a new parameter becomes needed we just add another signature so we don't break existing code. It solves so many headaches when sharing code between multiple consoles.

Edit: as a side note, try to avoid plain bool as a flag. Use an enum and specifically state what the thing is or is not. Today there are two choices, but tomorrow you may need a third.

Plus, new Object( MakeBobYourUncle.True ) ; is much less ambiguous than new Object( true ) ;

PARTNERS