milan.rajik
Banned
- Joined
- Apr 1, 2013
- Messages
- 2,524
- Helped
- 540
- Reputation
- 1,078
- Reaction score
- 524
- Trophy points
- 1,393
- Activity points
- 0
How to create an object of one class in another class? I am trying with both Visual Studio 2010 and NetBeans 1.7.3 IDE + MinGW Tool set.
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 class Greet{ public: Greet(string name){ //Constructor msg2 = name; } void SayHello(){ cout << msg2 << endl; } string msg2; private: string msg; //This is data member declaration }; class Greetings{ Greet myGreet1("Hi from Greet1"); //This line gives error public: Greetings(string name){ //Constructor msg = name; } void SayHello(){ cout << "From Object of class Greetings" << endl; } private: string msg; };