連続メモリに新しい配置を使用する際にいくつかの問題が発生しています。他に方法がある場合は、ガイドしてください。
私のコードを参照してください。
#include <new>
//================================================
class MyClass
{
private:
int ma;
public:
MyClass():ma(-1){}
};
//===========================================
int main()
{
// I am allocating the memory for holding 10 elements of MyClass on heap
void* pMyClass = ::operator new(sizeof(MyClass)*10);
//! Note :: the address of pMyClass1 and pMyClass will now point to same
//location after calling placement new
MyClass* pMyClass1 = :: new(pMyClass)MyClass();
//! Problem with this is that,
//! i can only instantiate the constructor for the base address. That is
//! pMyClass[0].
//! If i have to instantiate it for all the other instances,
//! that is pMyClass[1] to pMyClass[9], then how to do it ?
return 0;
}