0

It throws on code alike:

template<class T>
T* new_p(){
    T* result =  (T*) operator new (sizeof(T)); // HERE
    memset(result, 0, sizeof(T));
    result = new (result) T();
    return result;
}

enter image description here

enter image description here

So new does not work in VS2010 sometimes of I do something wrong?

4

2 回答 2

1

Most of the time, when you have heap assert errors like this, it means that you screwed something up earlier. It's probably not the current malloc/new you're executing that's the problem.

Perhaps you called free / delete twice for the same allocation, or you overran a heap-allocated buffer. These are often difficult to track down, unfortunately.

于 2013-04-08T16:42:05.643 回答
0

I've never seen new used like that. Maybe I'm not understanding what you are trying to do with that code, but this is how I would have thought it should be.

template<class T>
T* new_p(){
    T* result =  new T();
    memset(result, 0, sizeof(T)); //BTW, I doubt this will do good things
    return result;
}
于 2013-04-08T16:42:13.477 回答