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_C++11 - Fatal编程技术网

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
语句置于公共范围内。我已经更新了我的答案。