C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Re: is C++ implementation allowed to store object in non-con

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards
View previous topic :: View next topic  
Author Message
Falk Tannhäuser
Guest





PostPosted: Tue Jul 08, 2003 1:36 am    Post subject: Re: is C++ implementation allowed to store object in non-con Reply with quote



Mirek Fidler wrote:
Quote:
There is some indication that C++ implementation is allowed to store
base class suboject of derived class in different chunk of memory. Is
that true ? What paragraphs of standard deal with this issue ? (closest
I have found is 3.9/5, but it does not seems to be definitive).
Think about multiple virtual inheritance!

If eventually it is (personally, I do not think so), how is e.g.
placement operator new expected to work ?
_____________________________________

#include <new>
struct A {};

struct B1 : public virtual A {};
struct B2 : public virtual A {};

struct C : public B1, public B2 {};

unsigned char mem_for_B1[sizeof(B1)];
unsigned char mem_for_C[sizeof(C)];

int main()
{
// hoping the unsigned char arrays are well aligned...
B1* b1 = new(mem_for_B1) B1;
C* c = new(mem_for_C) C;
return 0;
}
_____________________________________
I don't think there is something special concerning placement new
since you can use it only to construct ***complete objects***
which always occupy a continuous memory zone (even if the B1 or
B1 subobjects within a C object doesn't).

Falk

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]


Back to top
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards All times are GMT
Page 1 of 1

 
 


Powered by phpBB © 2001, 2006 phpBB Group