class User
{
public:
std::string getName();
void changeName(std::string nName);
std::string getGroup();
void changeGroup(std::string nGroup);
User(std::string nName, std::string nGroup);
~User(void);
private:
std::string name;
std::string group;
};
现在我在Honeypot类中定义:
Honeypot.h:
class Honeypot
{
public:
User us;
我有构造函数:
Honeypot (std::string name, std::string ip, int numberOfInterfaces, std::string os);
在Honeypot.cpp中:
Honeypot::Honeypot(std::string name, std::string ip, int numberOfInterfaces, std::string os):us(nName, nGroup){
this->name = name;
this->ip = ip;
this-> numberOfInterfaces = numberOfInterfaces;
this->os = os;
}
但是这种语法不正确。错误是:
IntelliSense: expected a ')', 'nGroup' : undeclared identifier and more on line :us(nName, nGroup){...
感谢您的帮助。
答案 0 :(得分:1)
name和Group需要是Honeypot构造函数的参数;正如编译器指出的那样,它们是未声明的。
Honeypot::Honeypot(std::string name, std::string ip,
int numberOfInterfaces, std::string os,
std::string userName, std::string userGroup)
: us(userName, userGroup)
{
this->name = name;
this->ip = ip;
this->numberOfInterfaces = numberOfInterfaces;
this->os = os;
}