我试图在一个函数中引用一个对象,它给我一个“对象不可访问”的错误。这是有问题的头文件和 cpp 文件。
下面的客户头文件。我已将对象声明放在底部。
#pragma once
#include "bankAccount.h"
#include "checkingAccount.h"
#include "savingsAccount.h"
#include "address.h"
using namespace std;
class customer {
public:
customer(void);
customer(string,string);
~customer(void);
void setName(string n);
string getName();
void withdrawChecking(double);
void wihdrawSavings(double);
double depositSavings(double);
string print();
private:
string name
checkingAccount myChecking;
savingsAccount mySavings;
};
这是cpp文件。我已将问题陈述加粗。
#include "customer.h"
#include "checkingAccount.h"
customer::customer(void){
}
customer::customer(string n, string ac){
name = n;
mySavings.setAccount(ac);
myChecking.setAccount(ac);
}
void customer::setName(string n){
name = n;
}
string customer::getName(){
return name;
}
void withdrawChecking(double w){
myChecking.withdrawChecking(w);
}
那么最后一条语句和我的 header 有什么问题?
抱歉样式不好...第一次发布问题。
最佳答案
您在 withdrawChecking
的前面缺少一个 customer
。应该是:
void customer::withdrawChecking(double w)
关于C++ 对象不可访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20532816/