for (int i = 0; i < sn; i++) { infile2.read(reinterpret_cast<char*>(stu + i), sizeof(*(stu + i))); int size=0; infile2.read(reinterpret_cast<char*>(&size), sizeof(int)); for (int j = 0; j < size; j++) { PaymentRecords record; record.read(infile2); (stu+i)->AddPaymentRecord(record); } }class PaymentRecords { public: PaymentRecords() {}; PaymentRecords(int num, char* n,Date d); PaymentRecords(const PaymentRecords& payment); ~PaymentRecords() {}; void setPayment(int num, char* n, Date d); void setCost(double c); int getNum(); string getName(); string getPaytime(); Date getPayTime(); double getCost(); void read(ifstream& infile); private: int num; char name[20]; Date Paytime; double cost; };PaymentRecords::PaymentRecords(const PaymentRecords& payment) { num = payment.num; strcpy_s(name, payment.name); Paytime = payment.Paytime; cost = payment.cost; }这个复制构造函数调用的时候,进行完赋值操作后就会提示访问权限冲突
时间: 2024-03-14 07:47:37 浏览: 114
C++中的类型转换static_cast、dynamic_cast、const_cast和reinterpret_cast总结
这个错误提示是因为在复制构造函数中,你没有显式地声明为 public。默认情况下,类的成员和方法都是私有的,所以复制构造函数也需要声明为 public。你需要在类的定义中将复制构造函数的访问权限设置为 public,例如:
```
class PaymentRecords {
public:
PaymentRecords() {};
PaymentRecords(int num, char* n, Date d);
PaymentRecords(const PaymentRecords& payment);
~PaymentRecords() {};
void setPayment(int num, char* n, Date d);
void setCost(double c);
int getNum();
string getName();
string getPaytime();
Date getPayTime();
double getCost();
void read(ifstream& infile);
private:
int num;
char name[20];
Date Paytime;
double cost;
};
PaymentRecords::PaymentRecords(const PaymentRecords& payment) {
num = payment.num;
strcpy_s(name, payment.name);
Paytime = payment.Paytime;
cost = payment.cost;
}
```
这样就可以解决访问权限冲突的问题了。
阅读全文