3 に答える
5
Conversion constructors can only be defined for user defined types, in your case A
. However, they do not apply to fundamental types as pointers like A*
.
If doSomething
was taking an A const&
instead (or simply an A
), then the conversion constructor would be invoked as you expect.
于 2012-12-24T22:51:57.403 に答える
3
If you main requirement is to be able to call the existing doSomething function, then you can do this:
int main()
{
C* object = new C();
A a(object);
doSomething(&a);
// May need to delete object here -- depends on ownership semantics.
}
于 2012-12-24T22:57:12.220 に答える
0
おそらく、CをAのサブクラスにしたいということです。
class C : public A {
...
};
于 2012-12-24T23:04:46.870 に答える