在typedef中怀疑两个类中的一个类

编程入门 行业动态 更新时间:2024-10-26 09:33:56
本文介绍了在typedef中怀疑两个类中的一个类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有几个apd的类是2d和3d。 我已将apx从cxclass分离到新类cxclass1和cxclass2。 但是我有现有类的类...它不应该作为进程的一部分进行更改(通常我们应该使用typedef cxclass1 cxclass所以电话会转移到新班级。 但是这里我有两个课程,我们不能为两个班级做typedef我想要解决这个问题吗?

I have class which is several apis which are 2d and 3d . i have segregated the apis from the cxclass to new classes cxclass1 and cxclass2. But i have class for existing class ..which should not be changed as part of process (should generally we did typedef cxclass1 cxclass) so calls will shift to new class. but here i have two classes we cant to do typedef for two classes i want solution regrading this ?

class CDerived1 { public: //CDerived1() { cout << "I am Derived1 Constructor" << endl; } void print() { cout << " I am derived1" << endl; } void func1() { cout << "I am CDerived1 func1" << endl; } }; class CDerived2 { public: CDerived2() { cout << "I am Derived2 Constructor" << endl; } void print() { cout << " I am derived2" << endl; } void func2() { cout << "I am CDerived2 func2" << endl; } }; class CBase : public CDerived1, public CDerived2 { public: CBase() { cout << "I am Base Constructor" << endl; } void func1(){ ; } void func2(){ ; } }; void main() { CBase obj; obj.func1(); //obj.func2(); }

推荐答案

您似乎不明白 typedef 是什么...... 写行时 It seems that you do not understand what typedef is... When you write the line typedef type new_type

您实际上是为类型创建别名...为​​长类型名称创建速记非常有用...

you are actually create an alias for type...It is very useful to create shorthand for long type names...

typedef unsigned long ulong

在您的情况下,您尝试分配相同的多个类型的别名 - 这是不可能的,因为编译器无法确定你实际意味着什么类型... 如果我理解你的问题,你实际上是什么尝试做的是将一个类的功能分成两个类,但不想c改变现有的电话... 我建议的是创建 cxclass1 和 cxclass2 然后更改 cxclass 继承两个...这样你的退出调用仍将转到 cxclass ,但实际上执行 cxclass1 或 cxclass2 ...新代码可以直接访问新类... 一个例子...... ...之前

In your case you try to assign the very same alias to more than one types - that's impossible as the compiler will not able to decide what type you actually meant... If I understand you question, what you actually try to do is to separate functionality of one class into two classes, but do not want to change the existing calls... What I would advise is to create cxclass1 and cxclass2 and then change cxclass to inherit both...With this your exiting calls will still go to cxclass, but actually execute cxclass1 or cxclass2...New code can access the new classes directly... An example... ...before

class cxclass { public: DoSome() {} DoOther() {} }

...

...after

class cxclass1 { public: DoSome() {} } class cxclass2 { public: DoOther() {} } class cxclass : public cxclass1, public cxclass2 { }

更多推荐

在typedef中怀疑两个类中的一个类

本文发布于:2023-05-25 19:38:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/320887.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:类中   两个   typedef

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!