[BEGINNER] new keyword

L

Last Timer

I was asked in an interview if using new can we assign memory at a
known address. If yes, does it mean new operator can be overloaded like
others?

Thanks for your response
 
T

Thomas Matthews

Last said:
I was asked in an interview if using new can we assign memory at a
known address. If yes, does it mean new operator can be overloaded like
others?

Thanks for your response

Yes, yes. See the FAQ below.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.comeaucomputing.com/learn/faq/
Other sites:
http://www.josuttis.com -- C++ STL Library book
http://www.sgi.com/tech/stl -- Standard Template Library
 
R

Rolf Magnus

Last said:
I was asked in an interview if using new can we assign memory at a
known address.
Yes.

If yes, does it mean new operator can be overloaded like others?

Yes.
 
L

Last Timer

Checked the FAQ. Can someone please give examples of how new can be
overloaded/assign memory at a known address.

Thanks
 
P

Peter Koch Larsen

Last Timer said:
Checked the FAQ. Can someone please give examples of how new can be
overloaded/assign memory at a known address.

Thanks

void* adress = ... ;
myclass *mc = new(adress) myclass(...);

/Peter
 
K

Kanenas

void* adress = ... ;
myclass *mc = new(adress) myclass(...);

/Peter
This use of the new operator Peter shows is called "placement new" and
is covered in the C++ FAQ LITE in the section on destructors. If you
wish to use placement new, these portions of the FAQ are highly
recommended reading.

[11.10] What is "placement new" and why would I use it?
http://www.parashift.com/c++-faq-lite/dtors.html#faq-11.10

[11.14] Is there a way to force new to allocate memory from a specific
memory area?
http://www.parashift.com/c++-faq-lite/dtors.html#faq-11.14
 
H

Howard

Kanenas said:
This use of the new operator Peter shows is called "placement new" and
is covered in the C++ FAQ LITE in the section on destructors.

Funny place to put info on object construction, in the section on
destructors... :)
-H
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top