Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/145.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何从模板化派生类上的模板化基类调用成员?_C++_Templates_Token Name Resolution - Fatal编程技术网

C++ 如何从模板化派生类上的模板化基类调用成员?

C++ 如何从模板化派生类上的模板化基类调用成员?,c++,templates,token-name-resolution,C++,Templates,Token Name Resolution,使用此设置: template<int N> struct Base { void foo(); }; class Derived : Base<1> { static void bar(Derived *d) { //No syntax errors here d->Base<1>::foo(); } }; 有什么区别?为什么第二个会导致语法错误?在代码在Clang 3.2(请参阅)和GCC

使用此设置:

template<int N>
struct Base {
    void foo();
};

class Derived : Base<1> {
    static void bar(Derived *d) {
        //No syntax errors here
        d->Base<1>::foo();
    }
};

有什么区别?为什么第二个会导致语法错误?

在代码在Clang 3.2(请参阅)和GCC 4.7.2(请参阅)上编译良好的前提下,我看不出使用
Base:
:只需使用
d->foo()


你在用什么编译器?该死的,打字错误。这个问题是垃圾。
template<class E>
struct Base {
    void foo();
};

template<class E>
class Derived : Base<E> {
    static void bar(Derived<E> *d) {
        //syntax errors here
        d->Base<E>::foo();
    }
};
error: expected primary-expression before '>' token
error: '::foo' has not been declared
template<class E>
struct Base {
    void foo() { }
};

template<class E>
struct Derived : Base<E> {
    static void bar(Derived<E> *d) {
        //syntax errors here
        d->foo();
    }
};

int main()
{
    Derived<int> d;
    Derived<int>::bar(&d);
}
d->template Base<E>::foo();