Frage

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;
War es hilfreich?

Lösung

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top