Search for a name for names that are independent of the template parameter in VC ++ 2008 Express. This is mistake?

When experimenting with C ++ templates, I was able to create this simple code for which the output is different than I expected in accordance with my understanding of C ++ rules.

void bar(double d)
{
    std::cout << "bar(double) function called" << std::endl;
}

template <typename T> void foo(T t)
{
    bar(3);
}

void bar(int i)
{
    std::cout << "bar(int) function called" << std::endl;
}

int main()
{
    foo(3);
    return 0;
}

V++ 2008 Express, bar(int). , , bar(3); . . , , : " ++ , , , ". , " " bar foo void bar(double d);? , . bar.

+5
2

. , VS2005 ( Blogspot , . 1.3 ). -, VS2008.

int bar(double d) { return 0; }

template <typename T> void foo(T t) {
  int i = bar(3);
}

void bar(int i);

int main() {
  foo(3);
}

( Comeau Online), , VS , VS .

+3

AndreyT . , (§14.6.3/1):

void g(double);
void h();

template<class T> class Z {
public:
    void f() {
        g(1);    //calls g(double)
        h++;     //ill-formed: cannot increment function;
                 // this could be diagnosed either here or
                 // at the point of instantiation
    }
};

void g(int);     // not in scope at the point of the template
                 // definition, not considered for the call g(1)
+2

All Articles