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

一个关于继承类的例子,不知道哪儿错了?解决方案

2012-03-04 
一个关于继承类的例子,不知道哪儿错了?//tabtenno.h文件//基类的定义#ifndefTABTENN0_H_#defineTABTENN0_H

一个关于继承类的例子,不知道哪儿错了?
//tabtenno.h文件
//基类的定义
#ifndef   TABTENN0_H_
#define   TABTENN0_H_
//simple   base   class
//该类只是记录会员的姓名以及是否有球桌
class   TableTennisPlayer
{
private:
enum{LIM=20};
char   firstname[LIM];
char   lastname[LIM];
bool   hasTable;
public:
TableTennisPlayer(const   char   *fn= "none ",
                              const   char   *ln= "none ",bool   ht=false);
void   Name()const;
bool   HasTable()const{return   hasTable;};
void   ResetTable   (bool   v){hasTable   =v;};
};
//simple   derived   class
class   RatedPlayer:   public   TableTennisPlayer
{
private:
unsigned   int   rating;
public:
RatedPlayer(unsiged   int   r=0,const   char   *fn= "none ",const   char   *ln= "none ",bool   ht=false);
        RatedPlayer(unsigned   int   r,const   TableTennisPlayer   &   tp);
        unsigned   int   Rating(){return   rating;}
        void   ResetRating   (unsigned   int   r){rating=r;}
};

#endif


//tabtenn0.cpp文件
#include "tabtenn0.h "
#include "tabtenn1.h "
#include <iostream>
#include <string>
TableTennisPlayer::TableTennisPlayer(const   char   *fn,const   char   *ln,
  bool   ht)
{
        strncpy(firstname,fn,LIM-1);
firstname[LIM-1]= '\0 ';
strncpy(lastname,ln,LIM-1);
lastname[LIM-1]= '\0 ';
hasTable=ht;
}
void   TableTennisPlayer::Name()const
{
std::cout < <lastname < < ", " < <firstname;
}

//RatedPlayer   methods
RatedPlayer::RatedPlayer(unsigned   int   r,const   chr   *fn,
  const   char   *ln,bool   ht):TableTennisPlayer(fn,ln,ht)
{
rating=r;
}
RatedPlayer::RatedPlayer(unsigned   int   r,const   TableTennisPlayer   &tp)
      :TableTennisPlayer(tp),rating(r)
{

}


//测试文件
//usett0.cpp文件
#include <iostream>
#include "tabtenn0.h "
#include "tabtenn1.h "

int   main()
{
using   std::cout;
using   std::endl;
TableTennisPlayer   player1( "Tara ", "Boomdea ",false);
RatedPlayer   rplayer1(1140, "Mallory ", "Duck ",true);
        rplayer1.Name;
  if(rplayer.HasTable())
  cout < < ",has   a   table.\n ";
        else
  cout < < ",has 't   a   table.\n ";
  player1.Name;
          if(player1.HasTable())
  cout < < ",has   a   table.\n ";
                else  
  cout < < ",has 't   a   table.\n ";
          cout < < "Name: ";
          rplayer1.Name();
  cout < < ";Rating: "rplayer1.Rating() < <endl;
  RatedPlayer   rplayer2(1212,player1)


  cout < < "Name ";
  rplayer2.Name;
  cout < < ";Rating: " < <rplayer2.Rating() < <endl;

      return   0;
}



[解决办法]
你想问啥问题?请把你遇到的症状描述详尽些。

热点排行