I am creating a new class instance like this:
Cube* cube1;
There is code in the Cube constructor, but it’s not being run! Is this usual?
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’re actually not creating any instance.
the variable you’re calling
cube1is a pointer to aCube.To create a Cube you should have:
This create a new instance of Cube in heap memory, you should call
delete cube1once you don’t use it anymore.or:
This create a new instance of Cube in stack memory, it will be destroyed once it goes out of scope.
PS. you should get a C++ textbook.