【问题标题】:C++ Object inaccessibleC++ 对象不可访问
【发布时间】: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声明为一个函数,您应该在客户内部使用 :: 操作符来定义它的范围......

标签: c++ oop object scope


【解决方案1】:

withdrawChecking 前面缺少customer。应该是:

void customer::withdrawChecking(double w)

【讨论】:

  • 哇,谢谢。复制和粘贴总是会导致我失败。非常感谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-07-05
  • 1970-01-01
  • 2011-09-11
  • 2017-02-23
  • 1970-01-01
  • 1970-01-01
  • 2016-05-10
相关资源
最近更新 更多