2014-04-17 2 views
0

이 방법으로 명령 설계 패턴을 구현했지만 명령 클래스에서 소멸자의 주석을 제거하면 연결 오류가 발생합니다. 왜 ?C++의 명령 설계 패턴 문제

#include <iostream> 

using namespace std; 
//command design pattern 


class command 
{ 
public: 
    virtual void execute() = 0; 
    //virtual ~command(); 

}; 


class Receiver 
{ 
public : 
    void action() 
    { 
     cout<<" command executed "<<endl; 
    } 

}; 

class concreteCommand:public command 
{ 
    Receiver *_r; 
public: 
    concreteCommand(Receiver *r = 0) :_r(r) 
    {} 
    void setReceiver(Receiver *r = 0) 
    { 
     _r = r; 
    } 
    virtual void execute() 
    { 
     if(0!=_r) 
     { 
      _r->action(); 
     } 
    } 
}; 

class invoker 
{ 
    command *_c; 
public: 
    invoker(command* c):_c(c) 
    {} 
    void setCommand(command *c=0) 
    { 
     _c=c; 
    } 
    void invoke() 
    { 
     if(0!=_c) 
     { 
      _c->execute(); 
     } 
    } 

}; 





int main() 
{ 
    Receiver r; 
    concreteCommand c(&r); 
    invoker i(&c); 
    i.invoke(); 
    return 0; 
} 
+3

소멸자 기능을 구현하지 않으므로? –

답변

0

오류를 발견했습니다. 소멸자를위한 시신을 제공해야합니다.