Just a simple question. As the title suggests, I’ve only used the “new” operator to create new instances of a class, so I was wondering what the other method was and how to correctly use it.
Share
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.
You can also have automatic instances of your class, that doesn’t use
new, as:The last two are using placement-new which is slightly different from just new. placement-new is used to construct the object by calling the constructor. In the third example,
malloconly allocates the memory, it doesn’t call the constructor, that is why placement-new is used to call the constructor to construct the object.Also note how to delete the memory.
To know what is placement-new, read these FAQs: