In a C++ constructor do I have to allocate space for my instance fields (specifically I have two pointers as fields) or does calling “new” automatically allocate this space?
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.
No. Instance fields of your classes are automatically allocated. If they are pointers, space is allocated for your pointers (4 bytes on 32 bit architectures, 8 bytes on 64 bit architectures). If you want your pointers to point to objects, you will need to either assign them or create objects for them to point to.