开发者

Placement new in gcc

I need to find a workaround for a bug with placement new in g++. I now it was fixed in gcc-4.3 but I have to support versions 4.2 and 4.1. For example, following code compiles with an error

"error: no matching function for call to 'operator new(long unsigned int, void*&)"

template<class T, template<typename> class Alloc> 
inline void* type_ctor()
{
    Alloc<T> a; void* p = a.allocate(1);
    new(p) T;
 开发者_高级运维   return p;
}

.....

type_ctor<A, NewAllocator >();


To use the standard library placement news, you have to #include <new>.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜