Last weekend, I had a certain problem with the overload function, which I can not solve. The code below is a distillation problem:
#include <iostream>
using namespace std;
template<typename T>
void f(const T& t)
{
cout << "In template function." << endl;
}
class C
{
public:
void f() { cout << "In class function." << endl; }
void g() { int i=0; f(i); }
void h() { int i=0; f<int>(i); }
void i() { extern void f(int); int i=0; f(i); }
};
int main()
{
cout << "Test" << endl;
C c;
c.i();
return 0;
}
1) C :: g will not compile because the compiler will not try to use the template. He just complains that there is no C :: f to match.
2) C :: h will not compile without any reason that is obvious to me. Message "expected primary expression before" int "
3) C :: I will compile, but (after commenting g and h) it will not connect anything. I think I understand this: extern makes the linker look into another compilation unit, but any template definition will be in that compilation unit.
1 2. , , - , ?