-1
你能幫我用C++寫作嗎? 我有類用戶,誰載: User.h如何用C++編寫構造函數?
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.h:
class Honeypot
{
public:
User us;
我有構造函數:
Honeypot (std::string name, std::string ip, int numberOfInterfaces, std::string os);
in 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){...
謝謝你的幫忙。
您沒有將'nGroup'或'nName'定義爲參數。 –