Sign in to follow this  
Gamer Gamester

C++: 'signed int' called when passed 'unsigned char'

Recommended Posts

Gamer Gamester    140
My program has a bug that has been driving me crazy... and I finally located where it is and what is happening, but need some help. I have a function that is overloaded to take different types:
FunctionA( unsigned int p1 );
FunctionA( signed   int p1 );
FunctionA( std::string  p1 );
FunctionA( unsigned char p1 );
The trouble I'm having is that every time I pass a parameter of type 'unsigned char', the 'signed int' function gets called. Any idea why?

Share this post


Link to post
Share on other sites
daviangel    604
Quote:
Original post by BeauMN
Never mind!! I had left out the virtual definition for the 'unsigned char' function in an abstract base class. Stupid mistake that it took me an hour to find.

That's C++(fixed) for ya!

[Edited by - daviangel on February 19, 2008 4:46:05 PM]

Share this post


Link to post
Share on other sites
Dragon88    246
Quote:
Original post by daviangel
Quote:
Original post by BeauMN
Never mind!! I had left out the virtual definition for the 'unsigned char' function in an abstract base class. Stupid mistake that it took me an hour to find.

That's C for ya!


No, that would be C++. You would have no such problem in C.

Share this post


Link to post
Share on other sites
Zahlman    1682
Beware also of hiding.

Also, passing the string by const reference is probably a good idea.

Also, why do you have such a hairy set of overloads? What does the function do? Can't you use a template?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this