Placement syntax: Difference between revisions

Content deleted Content added
Rescuing 1 sources and tagging 0 as dead. #IABot (v1.6.5)
Default placement: deleted part starting with "In your case..." Probably copied from Stack Overflow, doesn't make sense here.
Line 84:
{ return here ; }
</source>
 
In your case, using this is not required as an int is [[Plain old data structure|POD]], it has a trivial constructor. If you want to use it, you could use it this way:<source lang="cpp" enclose=div>
 
for( int i = 0; i < MAX_PIXELS; i++ )
{
int* p = new (buffer+i) int(i) ; // specify where you want the object
v.push_back( p ) ;
cout << "p = " << p << ", *p = " << *p << endl ;
}
 
</source>
note: Do not call delete for objects allocated using placement new. If they have non-trivial destructors, call the destructor directly (destruction is an operation on an object and therefore can be called!). Release the memory you allocated yourself.
 
=== Preventing exceptions ===