Hi,
I got the following circular inclusion problem, and hope that
someone could show me some help here.
Code:
=============== ===
The compile errors below:
224 unix-machine[**]:/class/PATTERN-DESIGN/mediator% g++ webpage1.cc
webpage1.cc: In member function 'void Welcome::go()':
webpage1.cc:15: error: invalid use of undefined type 'struct Mediator'
webpage1.cc:6: error: forward declaration of 'struct Mediator'
*************** *************** ************
I understand the forward declaring will not allow me to call the member function on line 15, how do I go about resolving this on line 15? I tried to swap the placement of 2 classes, but no avail.
thanks,
Tera
I got the following circular inclusion problem, and hope that
someone could show me some help here.
Code:
=============== ===
Code:
1 #include <iostream>
2 #include <string>
3 using namespace std;
4
5 // class Welcome;
6 class Mediator;
7
8 class Welcome
9 {
10 public:
11 Welcome(Mediator* m)
12 { mediator = m; }
13
14 void go()
15 { mediator->handle("Welcome !!"); }
16
17 private:
18 Mediator* mediator;
19
20
21 };
22 class Mediator
23 {
24 public:
25 Mediator()
26 { welcome = new Welcome(this); }
27
28 void handle(string state)
29 { cout << state << endl; }
30
31 Welcome* getWelcome()
32 { return welcome; }
33
34 private:
35 Welcome* welcome;
36
37 };
38
39 int main()
40 {
41 Mediator* mediator = new Mediator();
42
43 mediator->getWelcome()->go();
44
45 delete mediator;
46 }
224 unix-machine[**]:/class/PATTERN-DESIGN/mediator% g++ webpage1.cc
webpage1.cc: In member function 'void Welcome::go()':
webpage1.cc:15: error: invalid use of undefined type 'struct Mediator'
webpage1.cc:6: error: forward declaration of 'struct Mediator'
*************** *************** ************
I understand the forward declaring will not allow me to call the member function on line 15, how do I go about resolving this on line 15? I tried to swap the placement of 2 classes, but no avail.
thanks,
Tera
Comment