I have a class
class Sample
{
string strName;
};
If i create an object for the Sample using Sample *obj = new Sample() where does the string strName created? is it in stack or in heap?
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.
Nowhere, because
Sample obj = new Sample()won’t compile.If you mean
Sample* obj = new Sample(), then it’s in dynamic storage (heap).When you call
delete obj, the string will be deleted automatically, even if it’s on the heap.