Question

you can typedef a data type:

typedef String std::string;

You can typedef a function

typedef String itos(int val);
itos std::to_string;

How can you typedef an overloaded function

eg.

typedef String to_string(all overloads);
to_string std::to_string;
Was it helpful?

Solution

In C++ overload mechanism allows to call functions with the same name but different argument types. Each overloaded function has different type (really they all are separate functions). For each such function compiler generates decorated names of the functions, adding parameter types to the function name, so that linker can distinguish them.

typedef does not create separate type. So, you cannot match several types to one typedef declaration, it is impossible. In C++11 you can use using type aliasing instead of typedef which has more clear syntax.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top