#include<iostream>
#include<cstring>
#ifndef TABTENNO_H_
#define TABTENNO_H_
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;
}
};
#endif
TableTennisPlayer::TableTennisPlayer(const char *fn , const char *ln , bool ht )
{
std::strncpy(firstname,fn,LIM-1);
firstname[LIM-1] = '\0';
std::strncpy(lastname,ln,LIM-1);
lastname[LIM-1] = '\0';
hasTable = ht;
}
void TableTennisPlayer::Name() const
{
std::cout<<lastname<<" ,"<<firstname;
}
int main(void)
{
using std::cout;
TableTennisPlayer player1("chuck","Blizzard",true);
TableTennisPlayer player2("Tarza","Boomdea",false);
player1.Name();
if(player1.HasTable()) //不可直接访问private 成员
{
cout<<":has a table.\n";
}else
{
cout<<":hasn't a table.\n";
}
player2.Name();
if(player2.HasTable())
cout <<":has a table.\n";
else
cout<<":hasn't a table.\n";
return 0;
}