[語法] 關於static data member
我的程式找不出問題
他出現
1>10.8.obj : error LNK2001: 無法解析的外部符號 "private: static double
savingaccount::annualInterestRate" (?annualInterestRate@savingaccount@@0NA)
1>MSVCRTD.lib(crtexe.obj) : error LNK2019: 無法解析的外部符號 _main 在函式
___tmainCRTStartup 中被參考
1>C:\Users\xxxx\Documents\Visual Studio 2008\Projects\10.8\Debug\10.8.exe :
fatal error LNK1120: 2 個無法解析的外部符號
我是要寫一個所有物件都能使用的 static data member
可是我寫了這些程式碼
我先po .h
#include <iostream>
using namespace std;
class savingaccount
{
friend ostream &operator<<(ostream cout,savingaccount & right);
friend istream &operator>>(istream cin ,savingaccount & right);
public:
savingaccount(int =0);
double calculatemonthlyinterest(void);
static void modifyinterestrate(double);
void savingsBalancecall(int);
double getbalance(void);
private:
static double annualInterestRate;
double savingsBalance;
double interest;
};
然後cpp的地方
我是寫
#include <iostream>
#include "10.8.h"
using namespace std;
double savingaccount::calculatemonthlyinterest(void)
{
interest=savingsBalance*annualInterestRate/12;
return interest;
}
void savingaccount::modifyinterestrate(double c)
{
annualInterestRate=c;
}
ostream &operator<<(ostream & cout,savingaccount & right)
{
cout<<right.getbalance();
return cout;
}
istream &operator>>(istream & cin ,savingaccount & right)
{
int a;
cin>>a;
right.savingsBalancecall(a);
return cin;
}
void savingaccount::savingsBalancecall(int b)
{
savingsBalance=b;
}
double savingaccount::getbalance(void)
{
return savingsBalance;
}
他出現一開始出現的問題
我不知道該怎麼解決
有人可以救我嗎.....我不知道問題出在哪
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.112.4.234
推
12/18 19:03, , 1F
12/18 19:03, 1F
→
12/18 19:03, , 2F
12/18 19:03, 2F
→
12/18 19:03, , 3F
12/18 19:03, 3F
→
12/18 19:05, , 4F
12/18 19:05, 4F
→
12/18 22:53, , 5F
12/18 22:53, 5F
→
12/18 22:54, , 6F
12/18 22:54, 6F
→
12/18 22:57, , 7F
12/18 22:57, 7F
→
12/18 23:01, , 8F
12/18 23:01, 8F
→
12/18 23:02, , 9F
12/18 23:02, 9F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章