a simpler "new" question

M

Mark P

I think my previous posts on this subject are too verbose and are
scaring off replies so I'll keep this one brief:

If I define my own operator new(size_t size) in a class, does that
automatically hide (global) placement new?

Would this prevent STL container classes from working (e.g., does
std::allocator require placement new for its construct() method?)?

Thanks for your help,
Mark
 
V

Victor Bazarov

Mark said:
I think my previous posts on this subject are too verbose and are
scaring off replies so I'll keep this one brief:

If I define my own operator new(size_t size) in a class, does that
automatically hide (global) placement new?

Yes, for that class only.
Would this prevent STL container classes from working (e.g., does
std::allocator require placement new for its construct() method?)?

That I am not sure of.

V
 
J

James Dennett

Victor said:
Yes, for that class only.




That I am not sure of.

I'd think, without checking, that std::allocator should call
global placement new... but I'll check...

And it's as well I did. It's apparently required to have the
same effect as:

new((void *)p) T(val)

which would not call global new if your class has an operator
new declared for it.

-- James
 
D

Dev

Mark said:
I think my previous posts on this subject are too verbose and are
scaring off replies so I'll keep this one brief:
If I define my own operator new(size_t size) in a class, does that
automatically hide (global) placement new?

Yes, It will hide only for the class in which you have defined new.

Would this prevent STL container classes from working (e.g., does
std::allocator require placement new for its construct() method?)?

No.
 
J

James Dennett

David said:
Well, std::vector<C> with VS .NET 2003 won't compile if class C does not
also provide placement new.

DW

As noted in my previous post, std::allocator::create is
required to use placement new.

-- James
 

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,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top