怎么侬都看不出那边有错,这个cpp文件到底怎么改?
h文件是#ifndef saving
#define saving
#include"account.h"
class Savings:public Account
{
public:
Savings(unsigned accNo,float balan=0.0);
virtual void Withdrawal(float amount);
protected:
static float minbalance;
};
#endif
cpp文件是#include
#include<iostream.h>
#include"account.h"
#include"saving.h"
static Savings::minbalance=500.0;
Savings::Savings(unsigned accNo,float balan=0.0):Account(accNo,balan){}
virtual void Saving::Withdrawal(float amount)
{
if(balance+minbalance<amount)
cout<<"You have no enough money!";
else
balance-=amount;
}
编译的时候 错误是:
C:\Program Files\Microsoft Visual Studio\MyProjects\ch16_2\savings.cpp(4) : error C2720: 'minbalance' : 'static ' storage-class specifier illegal on members
Error executing cl.exe.
去掉cpp文件中static又有如下错误:
C:\Program Files\Microsoft Visual Studio\MyProjects\ch16_2\savings.cpp(4) : error C2501: 'minbalance' : missing storage-class or type specifiers
C:\Program Files\Microsoft Visual Studio\MyProjects\ch16_2\savings.cpp(4) : error C2371: 'protected: static float Savings::minbalance' : redefinition; different basic types
c:\program files\microsoft visual studio\myprojects\ch16_2\savings.h(10) : see declaration of 'protected: static float Savings::minbalance'
Error executing cl.exe.
[ 本帖最后由 gaojiannew 于 2013-9-20 14:06 编辑 ]