C++ 虚拟模板函数重载
C++ 虚拟模板函数重载,c++,templates,c++11,C++,Templates,C++11,Child中的方法void blah(int)在Parent中隐藏继承的T blah()。您可以通过添加行来取消隐藏它 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(in
Child
中的方法void blah(int)
在Parent
中隐藏继承的T blah()。您可以通过添加行来取消隐藏它
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()
,则必须确保using
语句位于公共访问部分。所以你必须加上
using Parent::blah;
到Child
的顶部,使Parent::blah()
对所有人都可见。您还可以使用Parent::blah()
而不是只blah()
显式引用基类方法。更多信息可用。子中的方法void blah(int)
隐藏父中继承的T blah()
。您可以通过添加行来取消隐藏它
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()
,则必须确保using
语句位于公共访问部分。所以你必须加上
using Parent::blah;
到Child
的顶部,使Parent::blah()
对所有人都可见。您还可以使用Parent::blah()
而不是只blah()
显式引用基类方法。更多信息可用。您只是在child中有不同的原型。对于父级,它是T blah()
,对于子级,它是void blah(int)
,而它应该是double blah()
,以产生正确的虚拟函数重载
另外,您在parent中有Child模板参数做什么?您只是在Child中有不同的原型。对于父级,它是T blah()
,对于子级,它是void blah(int)
,而它应该是double blah()
,以产生正确的虚拟函数重载
另外,在父级中有子模板参数用于什么?谢谢。这解决了问题,我可以在课堂上使用它。。。但是,我不能在外部使用Parent::blah()。例如:p->blah();为此,您必须将using
语句置于公共范围内。我已经更新了我的答案。谢谢。这解决了问题,我可以在课堂上使用它。。。但是,我不能在外部使用Parent::blah()。例如:p->blah();为此,您必须将using
语句置于公共范围内。我已经更新了我的答案。