我有两个用户自定义类:我怎么投用户定义的类的指针,而无需使用继承
class A:class Base
{
type x;
doSomething();
}
class B
{
type x;
doSomething();
}
我也有一个功能,它获取类型库的变量,并使用dynamic_cast
将其转换为键入A并使用doSomething()。
class D : class Base2
{
D(Base _base1):Base2(Base _base1)
{
//here is the actual problem
}
void foo()
{
//b is a private member of class Base2 of type Base
A *a=dynamic_cast(b);
A->doSomething();
}
}
但我想传递B到这个函数,并且同时我不希望B继承自Base。
p.s我无权更改基地
这怎么可能?
你不这样做。请参阅[严格别名](http://stackoverflow.com/questions/98650/what-is-the-strict-aliasing-rule)为什么。 – WhozCraig 2013-02-13 07:22:56