这里我有一个错误,但我不知道为什么会显示。这是错误:
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;
};
利用.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);
}
我希望有人能帮助我,因为这对我来说很奇怪。
谢谢!!
最佳答案
您忘记包含字符串标题:
#include <string>
在 Command.hh
中。
在相关说明中,让构造函数接受 std::string
可能是个好主意:
Command(const std::string& exp) {
而不是 const char*
。
关于c++ - 对象 std::string 出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21525451/