在typedef中怀疑两个类中的一个类 [英] Doubt in typedef one class in two classes

查看:77
本文介绍了在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中怀疑两个类中的一个类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆