C ++のコンストラクターで新しく作成されたオブジェクトへのポインターを作成する方法を知りたいですか?
クラスの住所は何ですか?
class MyClass
{
public:
};
class MyClass2
{
public:
//I need a pointer to the created object
MyClass2 *pObjectName;
//Constructor
MyClass2()
{
pObjectName = &//I have no clue how to get the adress of the (not yet) created object.
}
};
int main()
{
//The way it works
//Makes Object
MyClass *pObject;
MyClass Object;
//pObject points to Object
pObject = &Object;
//Prints adress of Object
printf("%p", pObject);
//The way I would like to see it work
MyClass2 Object2;
//Prints adress of Object
printf("%p", Object2.pObjectName);
}