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

  • SEARCH
  • Home
  • 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 3720484
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T05:13:53+00:00 2026-05-19T05:13:53+00:00

This page (from C++ in action book) shows code: class Link { friend class

  • 0

This page (from C++ in action book) shows code:

class Link
{
    friend class FreeList;
public:
    Link (Link * pNext, int id)
    : _pNext (pNext), _id (id) {}

    Link *  Next () const { return _pNext; }
    int     Id () const { return _id; }
    // allocator
    void * operator new (size_t size)
    {
        assert (size == sizeof (Link));
        return _freeList.NewLink ();
    }
    void operator delete (void * mem)
    {
        if (mem)
            _freeList.Recycle (mem);
    }
    static void Purge () { _freeList.Purge (); }
private:
    static    FreeList _freeList;

    Link *  _pNext;
    int     _id;
};

And then say

Class Link has a static member
_freeList which is used by the overloaded class-specific operators
new and delete. Notice the assertion
in operator new. It protects us from
somebody calling this particular
operator for a different class. How
could that happen? Operators new and
delete are inherited. If a class
derived from Link didn’t override
these operators, new called for the
derived class would return an object
of the wrong size (base-class size).

Is this saying true? I think new will be called with right size of derived object. Why not?

  • 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-19T05:13:54+00:00Added an answer on May 19, 2026 at 5:13 am

    A new expression will cause an allocation function (operator new) to be called with the correct size for the object being constructed. That’s what the size_t parameter for operator new is for.

    The particular implementation of operator new in the example, however, can only cope with uniform sized allocation requests. If a derived class didn’t override operator new this implementation of operator new would be called with a size that it can’t cope with (aka “wrong”).

    It is, in general, perfectly possible to write an operator new for a class that can handle allocation requests for derived classes.

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

Sidebar

Related Questions

This page from Adobe says to add a wmode parameter and set its value
If you visit this page in Internet explorer, and choose a value from the
I have this query: SELECT page.id, revision.title, revision.number FROM page INNER JOIN revision ON
This is my first time attempting to call an ASP.NET page method from jQuery.
I am trying to execute this SQL command: SELECT page.page_namespace, pagelinks.pl_namespace, COUNT(*) FROM page,
I have a simple code from a book and the code should display data
In an ASP.NET MVC application I have a CartController with this AddToCart action: public
This is from a very good book by Steven Sanderson I am trying to
Here is a code snippet from my page: <input value=Search type=submit /><!-- whitespace --><span
In ASP.NET MVC I have a controller that looks somehow like this: public class

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.