⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 player.cpp

📁 构造函数和析构函数的多种用法
💻 CPP
字号:
#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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -