摘要:
近日发现开发的一个程序有个指针被重复删除了,跟踪检查后发现是虚函数不够‘虚’导致重复删除造成的。请看实例代码#include"stdafx.h"#include<iostream>classBase{public:Base(){fun();}virtual~Base(){fun();}virtualvoidfun(){std::cout<<"Base::fun"<<std::endl;}};classSub:publicBase{public:Sub(){fun();}~Sub(){fun();}virtualvoid 阅读全文
摘要:
IntArray arrTest;arrTest.append(1);arrTest.append(1);arrTest.append(1);arrTest.append(1);arrTest.append(1);arrTest.append(1);IntArray other;arrayForeachT(arrTest, BD<int>(&IntArray::append, BST::ref(other), _1)); // OKarrayForeachT(arrTest, BD<int>(&IntArray::append, &other, 阅读全文