#ifndef RESERVATIONS_H_INCLUDED
#define RESERVATIONS_H_INCLUDED
#include <vector>
#include <string.c>

class Reservations
{
public:
    Reservations::Reservations { }
    Reservations(string FullName, int PhoneNum);
    string getname() { return FullName; }
    int getnumber() { return PhoneNum; }
private:
    string FullName;
    int PhoneNum;
}

#endif // RESERVATIONS_H_INCLUDED

Reservations::Reservations(string FullName, int PhoneNum) //error on this line
{
    FullName = FullName;
    PhoneNum = PhoneNum;
}


我得到标题中的错误,我不知道为什么要假设我希望它拥有自己的类的成员...

最佳答案

您包含错误的头文件

更改

#include <string.c>




#include <string>


还要使用具有完整命名空间std的字符串。

下面的代码应进行较小的修复:

class Reservations
{
public:
    Reservations() : PhoneNum(0) {}
    Reservations(std::string FullName, int PhoneNum);
    std::string getname() { return FullName; }
    int getnumber() { return PhoneNum; }
private:
    std::string FullName;
    int PhoneNum;
};

Reservations::Reservations(std::string FullName, int PhoneNum)
{
   this->FullName = FullName;
   this->PhoneNum = PhoneNum;
}

// Better use member initializers list
Reservations::Reservations(std::string FullName, int PhoneNum)
: FullName(FullName),
  PhoneNum(PhoneNum)
{
}

10-04 18:49