本文介绍了C ++指针多继承乐趣的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我写一些代码涉及从基本的计数指针类继承;和一些复杂的C ++弹出。我已将其减少如下: 假设我有: class A {}; class B {}; class C:public A,public B {}; C c; C * pc =& c; B * pb =& c; A * pa =& c //指向一个有效的A对象? // pb指向一个有效的B对象? // pa = pb? 此外,还有: // pc ==(C *)pa? // pc ==(C *)pb? $ b 谢谢!解决方案 pb指向有效的B对象? / li> 是的, C * 以便 pa 和 pb 指向正确的地址。 是pa == pb吗? 不,通常不是。在同一地址不能有 A 对象和 B 对象。 此外, pc ==(C *)pa? pc ==(C *)pb? 该转换将指针转换回 C 对象的地址,因此两个等式都为真。 I'm writing some code involving inheritance from a basic ref-counting pointer class; and some intricacies of C++ popped up. I've reduced it as follows:Suppose I have:class A{};class B{};class C: public A, public B {};C c;C* pc = &c;B* pb = &c;A* pa = &c;// does pa point to a valid A object?// does pb point to a valid B object?// does pa == pb ?Furthermore, does:// pc == (C*) pa ?// pc == (C*) pb ?Thanks! 解决方案 does pa point to a valid A object? does pb point to a valid B object? Yes, the C* gets converted so that pa and pb point to the correct addresses. does pa == pb ? No, usually not. There can't be an A object and a B object at the same address. Furthermore, does pc == (C*) pa ? pc == (C*) pb ? The cast converts the pointers back to the address of the C object, so both equalities are true. 这篇关于C ++指针多继承乐趣的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-26 19:26