通过宏声明不同类型的对象 [英] Declaring different type of object via macro

查看:65
本文介绍了通过宏声明不同类型的对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要处理以下情况。



I need to handle below scenario.

class A()
{
   int i;
};

class B()
{
   int j;
};

class C
{
   int k;
};

class D
{
  int l;
}

class E:A
{
  MYMACRO obj
};



如果E类派生自A类,MYMACRO宏应该创建C类对象,而如果从B类MYMACRO宏派生的E类应该创建D类型的对象。



如何通过宏实现这个目标?



我的要求是我不应该提到对象的类型声明时。宏应该检查当前类是从这个还是那个派生的。然后它必须创建不同类型的对象。



如果除了使用宏还有其他任何解决方案请建议我吗?



我尝试过:



我对它进行了探讨但无法为我的方案找到解决方案。


If class E is derived from class A, MYMACRO macro should create object of type C whereas if class E derived from class B MYMACRO macro should create object of type D.

How to achieve this via macro?

My requirement is I should not mention the type of object while declaring.The macro should check whether the current class is derived from this or that.Then it has to create the object of different types.

If there is any other solution apart from using macro please suggest me?

What I have tried:

I explored on it but Could not get solution for my scenario.

推荐答案

参见 typeid Operator [ ^ ]。


这篇关于通过宏声明不同类型的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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