Function overload issues

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. , , - , ?

+5
5

: http://ideone.com/zs9Ar

:

Test
.

#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() { using ::f; int i=0; f(i); }
};

int main()
{
    cout << "Test" << endl;
    C c;
    c.g();
    return 0;
}
+2

, C::f f. ::f<int>(i).

+3

, , .

f f(int), # 1 (C:: f() :: f (int)).

"::" , . .

0

.

::f .

i() f, ( , ), .

0

++ "" . ( class C), , . , . , , . g .

h. - f . , < C::f.

::f, .

0

All Articles