求教:使用dynamic_cast,dev-c++可以通过,vc60, vc.net报非法错误??
letok 2003-08-26 10:16:28 一个简单程序,在vc60和vc.net里编译通过,运行报非法错误。在dev-c++中
没问题
// test.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "string"
#include "vector"
#include "iostream"
#include "fstream"
using namespace std;
class ZooAnimal //基类
{
public:
virtual void fn(){;}; //虚函数
protected:
private:
};
class Bear: public ZooAnimal //派生类
{
public:
void fn(){cout<<"abc"<<endl;}; //隐藏基类虚函数
protected:
private:
};
int _tmain(int argc, _TCHAR* argv[])
{
ZooAnimal *pZoo = new Bear; //基类指针指向派生类
Bear * pBear = dynamic_cast< Bear* >( pZoo ); //转换
return 0;
}