【发布时间】:2015-05-11 13:01:42
【问题描述】:
我有一个指向我创建的名为多边形的类的指针向量,它具有不同形状的派生类。相关代码如下所示:
int main() {
vector<polygon*> polygonVec;
polygonVec.push_back(new triangle(2,3,1,2,-1,-4, "triangle 1"));
polygon *tempPolygon;
tempPolygon = new rectangle(1,2,3,4,5,6,7,8, "rectangle 1");
polygonVec.push_back(tempPolygon);
for(vector<polygon*>::iterator itr = polygonVec.begin();
itr != polygonVec.end();
itr++)
{
cout<<*itr<<endl;
}
for(vector<polygon*>::iterator itr = polygonVec.begin();
itr != polygonVec.end();
itr++)
{
delete *itr;
}
polygonVec.clear();
当我在 Visual Studio 2012 中编译并运行它时,它会按预期运行并提供所需的输出,但最后会抛出以下错误
“调试断言失败……_BLOCK_TYPE_IS_VALID(pHead->nBlockUse)”。
谁能告诉我为什么会这样?
【问题讨论】:
-
那个签名图片是怎么回事?