Home » C++ » Created on the class object in c++

Created on the class object in c++

1. Title


assumes that CSomething is a class, and how many CSomething objects are created in memory when executing the following statements?


CSomething, a ();

CSomething, B (2);

CSomething c[3];

CSomething, &ra = B;

CSomething, d = B;

CSomething, *pa = C;

CSomething, *p = new, CSomething (4);




2. thinking,



the answer is 8, but the correct answer should be 6 (thank you XJP great God). The analysis is as follows:



CSomething (a); / / object is not created, but the definition of a function, not using the default constructor

CSomething B (2); / / create a
object with parameters
CSomething c[3]; / / create 3 free parameters of object

CSomething &ra = B; //ra references B, and no object
is created
CSomething d = B; / / call the default copy constructor to create an object, the value of B to d

CSomething *pa = C; / / a pointer to C, and no object.

CSomething new CSomething (*p = 4); / / a new object.




CSomething, a ();

CSomething, B (2);

CSomething c[3];

CSomething, &ra = B;

CSomething, d = B;

CSomething, *pa = C;

CSomething, *p = new, CSomething (4);

Latest

Hot Channels »