首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

帮小弟我看下这个程序哪里的有关问题.

2012-03-30 
帮我看下这个程序哪里的问题..checking.h-------------------------------#ifndef checking_h#defineCHECK

帮我看下这个程序哪里的问题..
checking.h
-------------------------------
#ifndef checking_h
 #define CHECKING_H

#include "account.h"
enum remit{remitbypost,remitbygable,other};
class checking:public account
{public:
  checking(int accno,float balan=0.0);
  virtual void withdrawal(float amount);
  void setremit(remit re);
protected:
  remit remittance;

};
#endif

checking.cpp
------------------
#include <iostream.h>
#include "account.h"
#include "checking.h"

checking::checking(int accno,float balan=0.0):account(accno,balan)
{ remittance=other;
}

virtual void checking::withdrawal(float amount)
{ float temp=amount;
  if(remittance=remitbypost)
  temp=amount+30;
  else if(remittance=remitbygable)
  temp=amount+60;
  if(balance<temp)
  cout<<"insufficient funds:balance "<<balance<<",withdrawal"<<temp<<endl;
  else
  balance-=temp;
}
 void setremit(remit re)
 {
  int remittance=re;
 }


savings.h
----------------------
#ifndef SAVINGS_H
 #define SAVINGS_H
#include "account.h"
class savings:public account
{ public:
  savings(int accno,float balan=0.0);
  virtual void withdrawal(float amount);
 protected:
  static float minbalance;

};
#endif

savings.cpp
---------------------
#include <iostream.h>
#include "account.h"
#include "savings.h"
float savings::minbalance=500.0;
savings::savings(int accno,float balan=0.0):account(accno,balan)
{}
virtual void savings::withdrawal(float amount)
{ if(balance+minbalance<amount)
{ int temp; cout<<"insufficient funds:balan"<<balance<<",withdrawal"<<temp<<endl;}
  else
  balance-=amount;
}

编译提示:
D:\c++\银行\checking.cpp(5) : error C2572: 'checking::checking' : redefinition of default parameter : parameter 2
  d:\c++\银行\checking.h(8) : see declaration of 'checking::checking'
D:\c++\银行\checking.cpp(10) : error C2723: 'withdrawal' : 'virtual' storage-class specifier illegal on function definition
savings.cpp
D:\c++\银行\savings.cpp(5) : error C2572: 'savings::savings' : redefinition of default parameter : parameter 2
  d:\c++\银行\savings.h(6) : see declaration of 'savings::savings'
D:\c++\银行\savings.cpp(8) : error C2723: 'withdrawal' : 'virtual' storage-class specifier illegal on function definition
执行 cl.exe 时出错.

16.10.exe - 1 error(s), 0 warning(s)

account.h 

这个没有问题...

请帮我看看这个是什么问题???


[解决办法]
checking::checking(int accno,float balan=0.0):account(accno,balan) 

checking::checking(int accno,float balan):account(accno,balan) 
默认参数只是在其声明时可见
[解决办法]
楼上说的意思就是那个缺省值0.0要去掉,因为缺省值只有在函数声明的时候才是合法的,你在类中声明这个函数的时候已经声明了这个缺省值,在实现的时候不要再写一次.

热点排行