Maybe this thread is a bit old, but if you are still interested, there is a problem with line 27. The:
Code:
Greet myGreet1("Hi from Greet1");
line cannot be in the class definition. What is happening is that you are trying to initialize a non-static member variable (myGreet1) in the class definition. This should instead occur in the constructor. You would probably want something like this:
Code:
class Greetings{
public:
Greetings(string name) // constructor
: myGreet1("Hi from Greet1") { //Constructor initializer list
msg = name;
}
void SayHello(){
cout << "From Object of class Greetings" << endl;
}
private:
string msg;
Greet myGreet1; // note that you declare the inner greet here
};
Now this will compile and run, but it won't print "Hi from Greet1", because your Greetings class doesn't tell the greet class to do anything other than run his constructor. You probably want to do something like the following:
Code:
class Greetings{
public:
Greetings(string name) // constructor
: myGreet1("Hi from Greet1") { //Constructor initializer list
msg = name;
}
void SayHello(){
myGreet1.SayHello(); // tell the inner greet to do something
cout << "From Object of class Greetings" << endl;
}
private:
string msg;
Greet myGreet1; // note that you declare the inner greet here
};
Anyways, let me know if you are still waiting on this and if this makes sense. Good Luck!