大佬教程收集整理的这篇文章主要介绍了c – 静态函数重载?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
>定义接口的基类:@R_709_9447@使用基类指针来访问函数.
>出于内存管理的目的(这是一个有限ram的嵌入式系统),我希望静态分配重写函数.我接受这样的结果:使用静态函数,我将如何操作函数中的数据.
我目前的想法是,我可以通过使其成为实际静态的函数的包装来保持轻量级重载函数.
请不要告诉我,我需要重新思考我的设计.这就是我提出这个问题的原因.如果你想告诉我我最好使用c并使用回调,请指导我阅读一些阅读材料来解释使用面向对象方法的缺陷.是否有面向对象的设计模式满足我列举的要求?
是的,简单的旧虚函数.你的愿望是“静态分配的最重要的功能”.虚拟功能是静态分配的.也就是说,实现这些函数的代码只存在一次,并且只在编译/链接时固定.根据您的链接器命令,它们可能与任何其他功能一样存储在闪存中.
class I { public: virtual void doit() = 0; virtual void undoit() = 0; }; class A : public I { public: virtual void doit () { // The code for this function is created statically and stored in the code segment std::cout << "Hello,"; } virtual void undoit () { // ditto for this one std::cout << "HelLO,"; } }; class B : public I { public: int i; virtual void doit() { // ditto for this one std::cout << "world\n"; } virtual void undoit() { // yes,you got it. std::cout << "WORLD\n"; } }; int main () { B b; // So,what is stored inside b? // There are sizeof(int) bytes for "i",// There are probably sizeof(void*) bytes for the vtable pointer. // Note that the vtable pointer doesn't change size,regardless of how // many virtual methods there are. // sizeof(b) is probably 8 bytes or so. }
以上是大佬教程为你收集整理的c – 静态函数重载?全部内容,希望文章能够帮你解决c – 静态函数重载?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。