C++ 语义问题:"'use of undeclared identifier 'balance'"
C++ Semantic issue: "'use of undeclared identifier 'balance'"
我是C++的新手,使用Xcode时遇到了问题,在我的主.cpp文件Account.cpp中,代码是-
#include <iostream>
using namespace std;
#include "Account.h"
Account::Account()
{
double balance=0;
balance=0;
}
Account getbalance()
{
return balance;
}
void deposit(double amount)
{
balance+=amount;
}
void withdraw(double amount)
{
balance-=amount;
}
void addInterest(double interestRate)
{
balance=balance*(1+interestRate);
}
我想我错过了什么,但我不知道在哪里,如果有任何帮助,我将不胜感激。谢谢。
**头文件Account.h是-
#include <iostream>
using namespace std;
class Account
{
private:
double balance;
public:
Account();
Account(double);
double getBalance();
void deposit(double amount);
void withdraw(double amount);
void addInterest(double interestRate);
};
以以下方式编写构造函数
Account::Account()
{
balance = 0.0;
}
我假设balance
是Account类的double
类型的数据成员。
或者你可以写
Account::Account() : balance( 0.0 ) {}
如果函数是类成员函数,那么所有这些函数定义都必须看起来至少像
double Account::getBalance()
{
return balance;
}
void Account::deposit(double amount)
{
balance+=amount;
}
void Account::withdraw(double amount)
{
balance-=amount;
}
void Account::addInterest(double interestRate)
{
balance=balance*(1+interestRate);
}
此外,您似乎忘记了使用参数定义构造函数。
Account::Account( double initial_balance ) : balance( initial_balance ) {}
相关文章:
- 我看到"use of undeclared identifier"错误,有人可以告诉我如何解决它吗?
- 消除"Undeclared identifier"错误
- 如何解决"if"块中的"Undeclared identifier error"?
- 使用类型类的向量时获取'undeclared identifier'
- "Use of undeclared identifier 'IntQueue' "即使它被定义
- Bazel 更新 GCC 后"undeclared inclusion(s)"错误
- 使用类作为向量类型时出错 - "Undeclared identifier"
- 在 Xcode 中使用 djinni 时"use of undeclared identifier" 'noreturn'
- TrySubmitThreadpoolCallback undeclared identifier
- 什么是'undeclared identifier'错误,如何解决?
- 使用 ios::Nocreate 标志会导致"undeclared identifier"错误
- 如何在Xcode中将长双精度转换为字符串格式?或如何解决错误"use of undeclared identifier 'to_string' "
- C++ 成员函数错误 在另一个成员函数中使用时"Undeclared Identifier"
- "error C2065: undeclared identifier" 来自另一个标头的枚举
- "Undeclared identifier"错误,如果尝试在 C++ 中的 Windows 下包含 libvlc
- wxDev-C++ - HtmlHelp undeclared
- SetWindowsHookEx HOOKPROC undeclared identifier
- 在 iOS 游戏中购买 Cocos2Dx "use of undeclared identifier"
- Unreal Engine 4.19 C++Undeclared Identifier错误,但它的代码是IS声明的
- "Use of undeclared identifier" - 代码有什么问题?