+ 3
using objects in class
Is it possible to use objects that are from other class abd use it in a different class? If so how? As the object is not declared when the class is being created.
1 Answer
+ 14
Composition.
class A
{
public: void speak() { std::cout << "Hi"; }
};
class B
{
public: void doStuff() { obj.speak(); }
private: A obj;
};
int main()
{
B obj;
obj.doStuff();
return 0;
}