I got the following snippet of codes which gave me the following
compile errors. I would really appreciate if anyone could tell
me what I have done wrong.
Expand|Select|Wrap|Line Numbers
- 1 #include <iostream>
- 2 #include <string>
- 3
- 4 class State;
- 5 class StateMachineInterface
- 6 {
- 7 public:
- 8 virtual void gotApplication() { }
- 9 virtual void checkApplication() { }
- 10 virtual void setState(State* s) { }
- 11 };
- 12
- 13 // class WaitingState;
- 14 class ConcreteStateMachine : public StateMachineInterface
- 15 {
- 16 public:
- 17 ConcreteStateMachine(int n)
- 18 {
- 19 waitingState = new WaitingState(this);
- 20 state = waitingState;
- 21 }
- 22
- 23 void gotApplication()
- 24 { cout << state->gotApplication(); }
- 25
- 26 void checkApplication()
- 27 { cout << state->checkApplication(); }
- 28
- 29 virtual void setState(State* s)
- 30 { state = s; }
- 31
- 32 private:
- 33 State* waitingState;
- 34 State* state;
- 35 };
- 36
- 37 class State
- 38 {
- 39 public:
- 40 virtual string gotApplication() = 0;
- 41 virtual string checkApplication() = 0;
- 42 };
- 43
- 44 class WaitingState : public State
- 45 {
- 46 public:
- 47 WaitingState(StateMachineInterface* a)
- 48 { automat = a; }
- 49
- 50 string gotApplication()
- 51 {
- 52 automat->setState(automat->getGotApplicationState());
- 53 return "Thanks for the application.";
- 54 }
- 55
- 56 string checkApplication()
- 57 { return "You have to submit an application."; }
- 58
- 59 private:
- 60 StateMachineInterface* automat;
- 61 };
- 62
- 63 int main()
- 64 { }
==========================
/class/PATTERN-DESIGN/state% g++ example.cc
example.cc: In method `ConcreteStateMachine::ConcreteStateMachine(int)':
example.cc:19: parse error before `('
example.cc: In method `void ConcreteStateMachine::gotApplication()':
example.cc:24: no matching function for call to `State::gotApplication ()'
example.cc: In method `void ConcreteStateMachine::checkApplication()':
example.cc:27: no matching function for call to `State::checkApplication ()'
example.cc: In method `class basic_string<char,string_char_traits<char>,__defau lt_alloc_template<false,0> > WaitingState::gotApplication()':
example.cc:52: no matching function for call to `StateMachineInterface::getGotApplicationState ()'
======================================
To start off, why does it complain about lines 19 and 24?
Thanks in advance,
PL