在'>'之前预期的初级表达式代币

时间:2015-04-20 09:56:46

标签: c++ templates c++98

  

也是重复的   Two templates in C++: "expected primary-expression before ‘>’ token"

基本上,我要做的是this

struct A {
    virtual ~A() {}
    virtual int bar() = 0;
};

struct B {
    int bar() {return 1;}
};

struct C {
    int bar() {return 2;}
};


struct D {
    template <class T>
    static int foo() {
        T a;
        return a.bar();
    }
};


template<class T, class U>
int callFoo() {
    return T::foo<U> (); ///error: expected primary-expression before '>' token
}


int main(int argc, char** argv) {
        std::cout << D::foo<B>() << std::endl; //This works of course
        std::cout << D::foo<C>() << std::endl; //This works of course
        std::cout << callFoo<D,B>() << std::endl;
        std::cout << callFoo<D,C>() << std::endl;
    }

如何调用作为函数参数模板的类的模板化静态方法?

0 个答案:

没有答案