Error

C++博客 首页 新随笔 联系 聚合 管理
  217 Posts :: 61 Stories :: 32 Comments :: 0 Trackbacks
class CBase
{
public:
int i[255];
};
class CSubA : public CBase
{
public:
int m_iA[255];
};
class CSubC : public CBase
{
public:
int m_iC[255];
};
class CSubSub : public CSubA, public CSubC
{
public:
int m_iss[255];
};
int _tmain(int argc, _TCHAR* argv[])
{
//CFieldManager fieldManager;
//fieldManager.RegisterType("", "", 1, 1);
//unsigned short i = 0x123;
//unsigned short usMax = USHRT_MAX;
//std::cout << std::setfill ('0') << std::setw(4) <<  std::hex << i << std::endl;
//std::cout << std::dec << 9 << std::endl;
//std::hash_map<std::string, std::string> testMap;
//std::string strTem;
//testMap["123"] = "123";
//testMap.find(strTem);
//double dResult = 2.f / 3.f;
//TestCounting();
//TestList();
//while (true)
{
CSubA * pSubA = new CSubA;
CBase * pBaseA = pSubA;
CSubC * pSubC = new CSubC;
CBase * pBaseC = pSubC;
std::cout << reinterpret_cast<unsigned int>(pBaseA) << std::endl;
std::cout << reinterpret_cast<unsigned int>(pSubA) << std::endl;
std::cout << reinterpret_cast<unsigned int>(pBaseA) << std::endl;
std::cout << reinterpret_cast<unsigned int>(pSubC) << std::endl;
delete pBaseA;
delete pBaseC;
CSubSub * pSubSub = new CSubSub;
CSubA * pSubATest =  pSubSub;
delete pSubATest;
pSubSub = new CSubSub;
CSubC* pSubCTest = pSubSub;
delete pSubCTest;
int i = 0;
}
return 0;
}
posted on 2013-03-19 17:58 Enic 阅读(722) 评论(2)  编辑 收藏 引用

评论

# re: C++多重继承时,用基类指针delete有坑 2013-03-20 09:47 剑孤寒
敢把基类加上虚析构函数么  回复  更多评论
  

# re: C++多重继承时,用基类指针delete有坑[未登录] 2013-03-22 13:46 enic
class CBase
{
public:
int i[255];

virtual ~CBase()
{
}
};

多谢大侠指点,加上以后能正常delete@剑孤寒
  回复  更多评论
  


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理