how does size get passed into new( size ) ?

Discussion in 'C++' started by Pallav singh, Apr 7, 2009.

  1. Pallav singh

    Pallav singh Guest

    Q how does size get passed into new( size ) ....when we are creating
    object ?


    class Base {
    public:
    static void * operator new(size_t size);
    ...
    };

    Base *p = new Base( ); // calls Base::eek:perator new!

    Thanks
    pallav singh
     
    Pallav singh, Apr 7, 2009
    #1
    1. Advertising

  2. Pallav singh wrote:
    > Q how does size get passed into new( size ) ....when we are creating
    > object ?


    How does any argument get passed into a function? Sometimes it's in the
    stack, sometimes it's in a register. The language Standard does not
    mandate any particular way of passing the arguments.

    > class Base {
    > public:
    > static void * operator new(size_t size);
    > ...
    > };
    >
    > Base *p = new Base( ); // calls Base::eek:perator new!


    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask
     
    Victor Bazarov, Apr 7, 2009
    #2
    1. Advertising

  3. Pallav singh

    Bo Persson Guest

    Pallav singh wrote:
    > Q how does size get passed into new( size ) ....when we are creating
    > object ?
    >
    >
    > class Base {
    > public:
    > static void * operator new(size_t size);
    > ...
    > };
    >
    > Base *p = new Base( ); // calls Base::eek:perator new!
    >


    The compiler knows the size of the object, sizeof(Base), and adds that
    parameter to the call.


    Bo Persson
     
    Bo Persson, Apr 7, 2009
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. dee
    Replies:
    9
    Views:
    527
    Joseph Byrns
    Apr 15, 2005
  2. soni29

    String passed into method

    soni29, Nov 8, 2003, in forum: Java
    Replies:
    8
    Views:
    433
    Thomas Schodt
    Nov 10, 2003
  3. Replies:
    18
    Views:
    531
    lilburne
    Jan 19, 2004
  4. Anand
    Replies:
    2
    Views:
    917
    Anand
    Sep 11, 2003
  5. Gabriel Genellina
    Replies:
    3
    Views:
    290
    hdante
    Dec 4, 2007
Loading...

Share This Page