What are the different way of creating object in c++ ?

Questions by vikas kushwah   answers by vikas kushwah

Showing Answers 1 - 4 of 4 Answers

Sainath Rao

  • Dec 6th, 2011
 

Different ways of creating an oject is

shape a = new shape();

a is the object creation of one typefor the shape class with new operator.

shape a;

This is another type of creation of object fot the class.

neeraj

  • Jan 3rd, 2012
 

You are not creating an object you are giving reference.

  Was this answer useful?  Yes

Isaac

  • Feb 21st, 2012
 

1. Create on stack. i.e. ClassA varA;
2. Create on heap. i.e. ClassA *ptrA = new ClassA;

  Was this answer useful?  Yes

NikunjSingh

  • Feb 22nd, 2012
 

1. using normal object creation: Shape obj;
2. copy ctor: Shape obj2=obj;// or Shape obj3(obj);
3. using new operator;

Code
  1. #include <iostream>

  2. "Shape...""Copy called""new....""allocation fail : no free memory"

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions