Hello all,
I am new to this forum and new to programming. In class, we recently went over composition and I am still having trouble getting my program to execute. I am thinking my professor just isn't explaining it to me in a way I can comprehend for practical use. I understand what I should be able to do, but actually implementing it and being able to use it universally is just not happening. Mainly, I am having trouble calling other objects from other classes into another class. I am sure the last thing someone wants to do is read my code, so I will do my best to refrain from that if possible. If anyone can just break it down differently, or possibly give a small example, it would be greatly appreciated. I love programming and refuse to let some small misunderstanding prevent my progress. Thank you in advance
#include <iostream>
using std::cout;
using std::endl;
class someClass
{
public:
int intInSomeClass;
};
class someOtherClass
{
public:
int intInSomeOtherClass;
someClass c;
};
int main()
{
someOtherClass instantiatedObject1; // Create an object of type someOtherClass
instantiatedObject1.intInSomeOtherClass=7; // this object contains an int called intInSomeOtherClass
instantiatedObject1.c.intInSomeClass=12; // .... and also contains an object of the type
// called someClass, where the instance of it is named 'c'
cout << instantiatedObject1.intInSomeOtherClass << " " << instantiatedObject1.c.intInSomeClass << endl;
return 0;
}
Two classes are defined, and one of them contains an instance of the other.