• Advertisement
Sign in to follow this  

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

This topic is 3659 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

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
Advertisement
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.

Share this post


Link to post
Share on other sites
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
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
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
Sign in to follow this  

  • Advertisement