Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

C++: How do I overload the "new" operator for placement new?

Consider the scenario:

    T* t = new T();

    X* x = new (t) X();

How would I do an overload of class T to allow this?

1 Answer

Relevance
  • ?
    Lv 7
    8 years ago
    Favorite Answer

    class T has no influence on how the statement X* x = new (t) X(); compiles. It will look for a suitable operator new (e.g. operator new(size_t, T*) or operator new(size_t, void*)) within the class scope of X, and then if none is provided there, in global scope, but it won't look inside T.

Still have questions? Get your answers by asking now.