Compiler error when using integer as template parameter

What is wrong with the following piece of code?

template<typename X>
struct A {
        template<int N>
        int foo() const {
                return N;
        }
};

template<typename X>
struct B {
        int bar(const A<X>& v) {
                return v.foo<13>();
        }
};

#include <iostream>
using std::cout;
using std::endl;

int main() {
        A<double> a;
        B<double> b;
        cout << b.bar(a) << endl;
        return 0;
}

Inside the function B::bar the compiler complains:

error: invalid operands of types ‘’ and ‘int’ to binary ‘operator<’

If A is not a template, everything compiles fine.

7
задан Prasoon Saurav 12 September 2010 в 11:34
поделиться