n**d 发帖数: 9764 | 1 How come this code crash in runtime by VC++ 6.0?
#include
using namespace std;
class Pet { public: virtual ~Pet(){}};
class Cat : public Pet {};
int main() {
Pet* b = new Cat; // Upcast
Cat* d = dynamic_cast(b);
} |
h*******e 发帖数: 225 | 2 VC6 is buggy. Use something else.
【在 n**d 的大作中提到】 : How come this code crash in runtime by VC++ 6.0? : #include : using namespace std; : class Pet { public: virtual ~Pet(){}}; : class Cat : public Pet {}; : int main() { : Pet* b = new Cat; // Upcast : Cat* d = dynamic_cast(b); : }
|
n**d 发帖数: 9764 | 3 How could it be in the market if it has so obvious bug?!
【在 h*******e 的大作中提到】 : VC6 is buggy. Use something else.
|
s***e 发帖数: 122 | 4 You could turn on the RTTI (in Project->Setting->C/C++->C/C++ Language) to
avoid this. You should have noticed the warning C4541: 'dynamic_cast' used
on polymorphic type ...
Anyway, this should be part of the C++ language, not an option.
【在 n**d 的大作中提到】 : How could it be in the market if it has so obvious bug?!
|
d***q 发帖数: 1119 | 5 vc 6.0 only covers 80% std c++,don't expect you can use tricks with this
compiler |