Advertisement Jump to content
Sign in to follow this  
nukomod

Function Overloading Ambiguity

This topic is 4101 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'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 this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by nukomod
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?


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

Share this post


Link to post
Share on other sites
Agreed. In general, having a single parameter of non-const-reference type is sketchy, especially if it's a primitive type.

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!