say we have
Class A{};
int *p = malloc(100);
A a; //default constructor in use
*p = A; (question???)
how to initialize an object of type A on alloc memory p?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
To instantiate a class instance at a specific address you need to use placement new.
Note that the destructor must be invoked explicitly when using placement new.