-1

你能帮我用 C++ 作曲吗?我有类用户,其中包含:User.h

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;
};

现在我在蜜罐类中定义:

蜜罐.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){...

谢谢你的帮助。

4

1 回答 1

2

nName 和 nGroup 需要作为蜜罐构造函数的参数;正如编译器所指出的,它们是未声明的。

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;
}
于 2013-05-29T22:35:27.533 回答