[问题] Call child class function from parent

楼主: gigigigi (gigigigi)   2017-09-23 09:43:23
开发平台(Platform): (Ex: Win10, Linux, ...)
Linux
编译器(Ex: GCC, clang, VC++...)+目标环境(跟开发平台不同的话需列出)
g++
https://gist.github.com/anonymous/f67031c9f2c237589ca2cf4214c86e1a
error: cannot call member function ‘void Derived<T>::toImplement(T&) [with T
= double]’ without object Derived<T>::toImplement(t);
Base<T>::tryUsingImplemented(t); // 这边从子类别函数 call 父类型函数ok
Derived<T>::toImplement(t); //但是从父类别函数 call 子类型函数不行
请问一下这是什么原因?
谢谢
楼主: gigigigi (gigigigi)   2017-09-23 10:03:00
virtual void toImplement(T& t) = 0; // 找到原因了加上这行
作者: LPH66 (-6.2598534e+18f)   2017-09-23 19:19:00
父 call 子本来就不是随便能做的父亲不会知道哪个子继承自己需要我去 call如果真的需要用到父 call 子这种写法的话可以去查 CRTPCRTP 利用了模版参数让父知道是哪个子继承自己
作者: Killercat (杀人猫™)   2017-09-27 22:39:00
CRTP...这会造成阅读跟除错困难 XD其实我私心认为 写code写成这样 应该逻辑也有问题了...建议把整个code逻辑展开看一下为什么非得这样做

Links booklink

Contact Us: admin [ a t ] ucptt.com