首页 > 解决方案 > 解决这个错误 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

标签: c++classstaticlnk2001

解决方案


推荐阅读