CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2009

    Placement new problem

    We have project that requires a special memory allocator so I am trying to overload the new and placement new operators. No matter what I try, I keep getting a syntax error from VS 2005 that says:
    error C2084: function 'void *operator new(size_t,void *) throw()' already has a body.

    Every article I Google and every C++ book I look at makes me think what I have should at least compile. My code is:

    inline void* operator new (size_t size)throw(std::bad_alloc)
    void *p=malloc(size);
    if (p==0) throw bad_alloc();
    return p;

    void* operator new (size_t size, void* p) throw()
    if (p==0) throw std::bad_alloc();
    return p;

    It is only the new with two parameters that generates errors, which leads me to think that it is defined somewhere inside a system library. The only thing I found when googling was that if _CRTDBG_MAP_ALLOC is defined it will cause this error but I am not using that. If anyone can point out where I'm going wrong I'd appreciate it.

  2. #2
    Join Date
    Feb 2011

    Re: Placement new problem

    Same problem here.....
    Please let me know if you have found the solution...

  3. #3
    Join Date
    Apr 2000
    Belgium (Europe)

    Re: Placement new problem

    If you have that 2nd form in a header and are including the header in more than one .cpp file, then yes, you're trying to generate copies of the operator in each of those .cpp files.

    The header shouldn't contain a body (body in a .cpp), or you need to declare it as inline as well like the 1st form.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.