C++ 对象不可访问

标签 c++ oop object scope

我试图在一个函数中引用一个对象,它给我一个“对象不可访问”的错误。这是有问题的头文件和 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/

相关文章:

java - 有界优先级队列继承与组合

javascript - ES6 OOP 从父类继承方法

php - 没有属性的对象可以吗?

c++ - 如果我想在 C++ 或 Java 中构建记录器类,它应该是单例还是静态的

c++ - 在 clang 中声明一个非别名变量?

c++ - 如何正确删除基类元素

javascript - 如何知道删除函数后数组/对象是否为空?

c++ - 光线追踪 GLSL - 位置移动时球体拉伸(stretch)

c++ - 为什么我不能在同一个代码行中创建和打开一个 ofstream?

java - 如何自动将用户定义的对象存储到 map 中?