- 论坛徽章:
- 0
|
test.h
#include "stdio.h"
#include "stdlib.h"
#inlcude <string>
using namespace std;
template <class T>
class TObjNew {
T* _t;
public:
TObjNew(void* _p, const int nCount) {
_t = (T*)_p;
_t = new(_t) T[nCount];
}
~TObjNew() {
delete [] _t;
}
};
test.cpp
#include "test.h"
struct STest {
string m_strTmp;
int m_nTmp;
};
char* pTmp = new char[1024];
int main(int argc, char** argv) {
TObjNew<STest> obj(pTmp, 4);
return 0;
}
为什么在析构的时候,会报内存错误而崩掉。
经调试,发现在在调用析构的时候又调用了构造函数,请高手分析以上程序的错误之处。感谢。
[ 本帖最后由 chenlihuiabc 于 2007-11-5 13:30 编辑 ] |
|