How an object of a class that contain object of other class created in C plus plus?

1 answer

Answer

1243410

2026-04-27 15:50

+ Follow

An object is a thing that occupies memory, has a value, and has methods that manipulate it. As such, even elementary variables are objects.

Most, however, consider that an object in C++ is an instance of a class type.

// declaration and definition

class myClass {

... attributes

... methods

... constructors

... destructor

};

// instantiation by direct allocation

myClass myClassObject;

// instantiation by heap allocation

myClass *myClassObjectPtr = new myClass;

ReportLike(0ShareFavorite

Copyright © 2026 eLLeNow.com All Rights Reserved.