【发布时间】:2011-04-14 11:47:19
【问题描述】:
我想了解一些关于在这种情况下比较指针时的最佳做法的信息:
class Base {
};
class Derived
: public Base {
};
Derived* d = new Derived;
Base* b = dynamic_cast<Base*>(d);
// When comparing the two pointers should I cast them
// to the same type or does it not even matter?
bool theSame = b == d;
// Or, bool theSame = dynamic_cast<Derived*>(b) == d?
【问题讨论】:
标签: c++ inheritance pointers dynamic-cast