template <class T, class U, class Child>
class Parent {
public:
virtual T blah() {
return gaga;
}
protected:
T gaga;
};
class Child : public Parent<double, double, Child> {
virtual void blah(int overloaded) {
}
virtual void func() {
blah();
}
};
int main() {
Child* p = new Child();
}
为什么上面的代码不能编译?为什么我不能像这样重载我的虚拟功能?虚拟模板功能过载
我得到的错误:
prog.cpp: In member function ‘virtual void Child::func()’:
prog.cpp:16: error: no matching function for call to ‘Child::blah()’
prog.cpp:12: note: candidates are: virtual void Child::blah(int)
prog.cpp: In function ‘int main()’:
prog.cpp:21: warning: unused variable ‘p’
谢谢。这解决了问题,我可以在课堂上使用它......但是,我不能使用Parent :: blah()以外的内容。例如:p-> blah(); – user988098 2012-02-03 20:39:38
为此,您必须将'using'语句放在公共范围内。我已经更新了我的答案。 – 2012-02-03 21:20:07