Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Overloading member methods with typedef aliases as parameters

I’m having some trouble overloading methods in C++.

typedef char int8_t;
class SomeClass{
public:
…
void Method(int8_t paramater);
void Method(char paramater);
};

Since int8_t is typedef as char they are just aliases, they may refer to the same type in which case overloading won’t work.

I want to make them work at the same time? Can you suggest solution to the same. Note: I do not want to add templated method.

Following is the error:

Error: Multiple declaration for SomeClass::Method(char)

like image 246
user1393608 Avatar asked Feb 20 '23 12:02

user1393608


1 Answers

Use a faux type. Wrap one of char or int8_t in a structure and use the structure as a parameter.

like image 156
dirkgently Avatar answered Mar 09 '23 05:03

dirkgently