什么是模板类中虚函数的解决方法?

时间:2016-12-15 21:45:10

标签: c++ templates

我正在尝试编译:

template <class L>
class A
{
        virtual int doIt() = 0;
};

template <class L>
class B : public A<L>
{
        int doItAgain() { return doIt(); }
};

int main()
{
}

并收到错误:

3.cc: In member function ‘int B<L>::doItAgain()’:
3.cc:11:32: error: there are no arguments to ‘doIt’ that depend on a template parameter, so a declaration of ‘doIt’ must be available [-fpermissive]
  int doItAgain() { return doIt(); }
                                ^
3.cc:11:32: note: (if you use ‘-fpermissive’, G++ will accept your code, but allowing the use of an undeclared name is deprecated)

用g ++。 clang也会出错:

3.cc:11:27: error: use of undeclared identifier 'doIt'
        int doItAgain() { return doIt(); }
                                 ^
1 error generated.

0 个答案:

没有答案