【发布时间】:2013-12-12 00:34:10
【问题描述】:
我试图在函数中引用一个对象,它给了我一个“对象不可访问”的错误。这是有问题的头文件和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);
}
那么最后一条语句和我的标题有什么问题?
抱歉样式不好……第一次发问题。
【问题讨论】:
-
您将withdrawChecking声明为一个函数,您应该在客户内部使用 :: 操作符来定义它的范围......