Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > how does size get passed into new( size ) ?

Reply
Thread Tools

how does size get passed into new( size ) ?

 
 
Pallav singh
Guest
Posts: n/a
 
      04-07-2009
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:perator new!

Thanks
pallav singh
 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      04-07-2009
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: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
 
Reply With Quote
 
 
 
 
Bo Persson
Guest
Posts: n/a
 
      04-07-2009
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:perator new!
>


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


Bo Persson


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Just passed passed my 3rd test for MCAD David MCAD 1 12-16-2005 06:04 PM
Session("passed") = Session("passed") + 1 error dee ASP .Net 9 04-15-2005 10:47 AM
Just to share my happyness: Passed today 70-290! First try...and passed ;) Hugo Sousa MCSE 12 04-02-2005 12:16 AM
Python C extension: Value different if passed as list than if passed as number Anand Python 2 09-11-2003 01:02 AM



Advertisments