how does size get passed into new( size ) ?

P

Pallav singh

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
 
V

Victor Bazarov

Pallav said:
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
 
B

Bo Persson

Pallav said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top