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.

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 on other sites
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 on other sites
Quote:
 Original post by BeauMNNever 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 on other sites
Quote:
Original post by daviangel
Quote:
 Original post by BeauMNNever 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 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?

• 9
• 49
• 11
• 17
• 11