对象std :: string出错

时间:2014-02-03 10:55:18

标签: c++ class object constructor stdstring

这里我有一个错误,但我不知道它为什么显示。这是错误:

In file included from Exploit.cc:2:0: Command.hh:35:17: error: field
 ‘_value’ has incomplete type Command.hh: In constructor
 ‘Command::Command(const char*)’: Command.hh:27:3: error: ‘_value’ was
 not declared in this scope make: *** [Exploit.o] Error 1

这是Command.hh

class Command {
public: 
    Command(const char* exp){
        _value=exp;
        _value.append("\n");
    }
    ~Command();
    void request(int fd);
    void response(std::string res);
    const char*  getCommand();
private: 
    std::string _value;
};

Exploit.cc

typedef std::shared_ptr<Command> CommandPtr;
typedef std::list<CommandPtr> CommandQueue; 
typedef std::shared_ptr<CommandQueue> CommandQueuePtr; 

Exploit::Exploit(const char* exp, int fd2, int type2): fd(fd2), type(type2){
    commands_to_execute = make_shared<CommandQueue>();
    commands_executed = make_shared<CommandQueue>();
    CommandPtr pr=std::make_shared<Command>( exp);
    commands_to_execute->push_back(pr);  
}

我希望有人可以帮助我,因为这对我来说非常奇怪。

谢谢!

1 个答案:

答案 0 :(得分:1)

您忘了包含字符串标题:

#include <string>
Command.hh中的


在相关的说明中,也许让构造函数接受std::string是个好主意:

Command(const std::string& exp) {

而不是const char*