|
-
February 24th, 2008, 09:22 AM
#1
C++ new operator weird syntax
Hi,
I was reading the E Appendix of "The C++ Programming Language , Special Edition" when I came across on page 948 with the following syntax:
"new(b.space) T(x);" where b.space is a pointer and x an object of type T. Does this syntax works in modern C++ compilers?
Thank you
-
February 24th, 2008, 09:31 AM
#2
Re: C++ new operator weird syntax
Why not test and find out for yourself? Or if you want others to help you test, then post the smallest and simplest program that you expect to be compilable. Not everyone has a copy of TC++PL.
-
February 24th, 2008, 09:45 AM
#3
Re: C++ new operator weird syntax
This is called placement new, and basically it's for constructing objects at a particular (pre-allocated) memory address without allocating anything. In the TC++PL example, a copy of x will be constructed at the address pointed to by b.space.
- Alon
-
February 24th, 2008, 10:10 AM
#4
Re: C++ new operator weird syntax
In any reasonably optimizing compiler, this is identical to
Assuming a copy constructor or operator= exists for the class. If x really is of type T, then I assume it does; in which case it's effectively the same as
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|