player.cpp

来自「构造函数和析构函数的多种用法」· C++ 代码 · 共 71 行

CPP
71
字号
#include<iostream>
#include"player.h"
using namespace std;
//Class PlayerId 
PlayerId::PlayerId(int number=8){
    playerid=number;
    cout<<"PlayerId is: "<<playerid<<endl;    
}

PlayerId::~PlayerId(){
    cout<<"Best wishes to the player with NO."<<playerid<<endl;    
}

//Class Player 
Player::Player(){
    cout<<"A Player is entering the court"<<endl;
}

Player::Player(int number):teamid(number){
    cout<<"A Player "<<teamid<<"is entering the court"<<endl;
}

Player::Player(char * name){
    cout<<name<<" is entering the court"<<endl;    
} 

Player::Player(char* name,int num):id(num){
    cout<<name<<" is entering the court"<<endl;    
}

Player::Player(Player&player){   
   cout<<"A fake copy of Player is constructed"<<endl;   
} 

Player::~Player(){
    cout<<"Best wishes to the Player"<<endl;
    name[0]='\0';
    delete name;    
}

//Class HardworkingPeople 
HardworkingPeople::HardworkingPeople(){
    cout<<"A HardworkingPeople is entering the court"<<endl;
}

HardworkingPeople::~HardworkingPeople(){
    cout<<"Best wishes to the HardworkingPeople"<<endl;    
}

//Class Noble 
Noble::Noble(){
    cout<<"A Noble is entering the court"<<endl;
}

Noble::~Noble(){
    cout<<"Best wishes to Noble"<<endl;    
}

//Class GreatestPlayer 
GreatestPlayer::GreatestPlayer(){
    cout<<"A GreatestPlayer is entering the court"<<endl;
}

GreatestPlayer::GreatestPlayer(int number):Player(number){
    cout<<"A GreatestPlayer is entering the court"<<endl;
}

GreatestPlayer::~GreatestPlayer(){
    cout<<"Best wishes to the GreatestPlayer"<<endl;    
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?