I'm a little confused about the template member functions, suppose we have some weird structure with a template member function, like this:
struct Foo { template <typename T> void f(T t) {}; };
And then we save this structure in some standard container:
std::vector<Foo> V; V.push_back(Foo()); V.push_back(Foo()); V.push_back(Foo()); V.push_back(Foo());
Further; let it call different instances of the template member function:
V.at(0).f<int>(1); V.at(0).f<char>(2); V.at(1).f<float>(3.4f); V.at(2).f<double>(5.6); V.at(3).f<long>(7);
And finally, the questions:
¿Do all instances of the class Foo belong to the same class? the answer seems to be yes, but ... the first instance of Foo has two overloads of the f member function at the end:
[0] Foo::f(int t); [0] Foo::f(char t);
And on the other hand, other instances of Foo seem to have only one version of f. Thus, the underlying type of each instance seems to be different due to differences in member functions.
[1] Foo::f(float t); [2] Foo::f(double t); [3] Foo::f(long t);
. If the functions f are given? , we can get the address of the function Foo :: f (int t) only from the first instance of Foo, because this function belongs only to this instance; same for other functions.
Thanks in advance.
source share