• Popular Now

• 11
• 9
• 10
• 9
• 11

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

Recommended Posts

I've got a problem with function overloading in C++, I'd be grateful if anyone could help out. Say I have these two functions.... void SomeFunc( int& intbyref ); void SomeFunc( int intcopy ); How do I tell the compiler which one I want to use?

Share on other sites
Cast the argument to a constant integer. Then, only the second one will be usable.

Share on other sites
Aha! Thank you :D

Share on other sites
Quote:
 Original post by nukomodI've got a problem with function overloading in C++, I'd be grateful if anyone could help out. Say I have these two functions....void SomeFunc( int& intbyref );void SomeFunc( int intcopy );How do I tell the compiler which one I want to use?

That's not a good design.
If those functions do different things then they should have different names.
If those functions do the same thing, but one changes the passed in value then it should be:
  int SomeFunc (int intcopy);

Hoping that you'll remember in the future to cast the value to a const int to preserve the value will lead to bugs. Having the same name do two different things will also lead to confusion in the future.

Skizz