c++ - 解决这个错误 unresolved external symbol LNK2001
问题描述
正如我在标题中提到的那样,我遇到了一个错误。
下面是代码
#include <iostream>
using namespace std;
class SavingsAccount {
private:
double savingsBalance;
static double AnnualInterestRate;
public:
static void ModifyInterestRate(double rate) {
AnnualInterestRate = rate;
}
double calculateMonthlyInterest(double bal) {
double total, newbal;
total = (bal * AnnualInterestRate) / 12;
newbal = bal + total;
return newbal;
}
};
int main(){
SavingsAccount saver1,saver2;
double s1, s2;
SavingsAccount::ModifyInterestRate(0.03);
s1 = saver1.calculateMonthlyInterest(2000.00);
s2 = saver2.calculateMonthlyInterest(3000.00);
cout << "Monthly Interest Saver 1: " << s1 << endl;
cout << "Monthly Interest Saver 2: " << s2 << endl;
SavingsAccount::ModifyInterestRate(0.04);
s1 = saver1.calculateMonthlyInterest(2000.00);
s2 = saver2.calculateMonthlyInterest(3000.00);
cout << "Monthly Interest Saver 1: " << s1 << endl;
cout << "Monthly Interest Saver 2: " << s2 << endl;
return 0;
}
问题出在静态双年利率成员上。我已尝试修复此问题 3 小时,但仍然无法帮助我的眼睛受伤。
错误:
Error LNK2001 unresolved external symbol "private: static double SavingsAccount::AnnualInterestRate" (?AnnualInterestRate@SavingsAccount@@0NA)
Error LNK1120 1 unresolved externals
解决方案
推荐阅读
- java - Google Drive API V3 下载返回 416 错误
- amazon-web-services - 负载均衡器初始请求容量
- javascript - 列表正在更新,但相应的本地存储未更新
- thrift - 异常结束时的 Thrift 消息
- c# - json反序列化为C#中的对象
- java - 如何使用水平滚动条(通过 xpath) - Selenium/Java
- visual-studio-code - 用于运行当前单元格但不将光标移动到 Jupyter for VS Code 中的下一个单元格的键盘快捷键?
- c++ - 为什么我会收到“运行时检查失败 #2 - 围绕变量 'pr' 的堆栈已损坏”错误?
- html -
等在 Swift String - javascript - CSS - 幻灯片文本背景