Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1808682
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T06:17:32+00:00 2026-05-17T06:17:32+00:00

Wikipedia states: A type can be made impossible to allocate with operator new: struct

  • 0

Wikipedia states:

A type can be made impossible to allocate with operator new:

struct NonNewable {
    void *operator new(std::size_t) = delete;
};

An object of this type can only ever be allocated as a stack object or as a member of another type. It cannot be directly heap-allocated without non-portable trickery. (Since placement new is the only way to call a constructor on user-allocated memory and this use has been forbidden as above, the object cannot be properly constructed.)

Deleting operator new is similar to making it private in current C++, but isn’t explicitly using global operator new, which avoids class-specific lookup, still valid C++0x?

NonNewable *p = ::new NonNewable();
// neither non-portable nor trickery, though perhaps not widely known

Have I missed something in the draft?


To be clear, this is valid C++03 and works fine:

struct NonNewable {
private:
  void *operator new(std::size_t);  // not defined
};

int main() {
  // ignore the leaks, it's just an example

  void *mem = operator new(sizeof(NonNewable));
  NonNewable *p = ::new(mem) NonNewable();

  p = ::new NonNewable();

  return 0;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T06:17:33+00:00Added an answer on May 17, 2026 at 6:17 am

    I believe you are right and wikipedia is wrong. The C++0x draft standard describes "deleted functions" (8.4p10) as functions which may not be used in any way (or else the program is ill-formed). They play no part in scope or name lookup different from normal functions. And the relevant paragraphs concerning new expressions have remained the same:

    [5.3.4p8] A new-expression obtains storage for the object by calling an allocation function (3.7.4.1). …

    [5.3.4p9] If the new-expression begins with a unary :: operator, the allocation function’s name is looked up in the global scope. Otherwise, if the allocated type is a class type T or array thereof, the allocation function’s name is looked up in the scope of T. If this lookup fails to find the name, or if the allocated type is not a class type, the allocation function’s name is looked up in the global scope.

    So yes, the expression ::new NonNewable [or ::new(mem) NonNewable] would choose an overload of ::operator new, ignoring the function NonNewable::operator new, and would not make the program ill-formed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Wikipedia states: In practice, explicit right outer joins are rarely used, since they can
The wikipedia article about Law of Demeter says: The law can be stated simply
Wikipedia says SQL Server Express Edition is limited to one processor, 1 GB memory
Wikipedia says Ruby is a functional language, but I'm not convinced. Why or why
Wikipedia has this to say: Total functional programming (also known as strong functional programming,
Wikipedia provides a number of citations used in the sciences , however does one
Wikipedia allows you to reproduce its content. If you want to use Wikipedia materials
From Wikipedia : Generic programming is a style of computer programming in which algorithms
From Wikipedia, the free encyclopedia: Closure (computer science) In computer science, a closure is
From wikipedia: the cross product is a binary operation on two vectors in a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.