欧美大屁股bbbbxxxx,狼人大香伊蕉国产www亚洲,男ji大巴进入女人的视频小说,男人把ji大巴放进女人免费视频,免费情侣作爱视频

歡迎來到入門教程網(wǎng)!

C語言

當(dāng)前位置:主頁 > 軟件編程 > C語言 >

關(guān)于C++復(fù)制構(gòu)造函數(shù)的實(shí)現(xiàn)講解

來源:本站原創(chuàng)|時(shí)間:2020-01-10|欄目:C語言|點(diǎn)擊: 次

復(fù)制構(gòu)造函數(shù)是一種特殊的構(gòu)造函數(shù),有一般構(gòu)造函數(shù)的特性。它的功能是用一個(gè)已知的對象來初始化一個(gè)被創(chuàng)建的同類對象。復(fù)制構(gòu)造函數(shù)的參數(shù)傳遞方式必須按引用來進(jìn)行傳遞,請看實(shí)例:

#include <iostream>
#include <cstring>
using namespace std ; 
class Student 
{
 private :
 char name[8];
 int age ;
 char sex ; 
 int score ;
 public :
 void disp(); //打印信息的函數(shù)聲明
 Student(char name[],int age , char sex ,int score); //構(gòu)造函數(shù)聲明
 Student(Student &dx); //復(fù)制構(gòu)造函數(shù)的聲明
 ~Student(); //析構(gòu)函數(shù)的聲明
};
//打印信息函數(shù)的實(shí)現(xiàn)
void Student::disp()
{
 cout << this->name << endl ; 
 cout << this->age << endl ; 
 cout << this->sex << endl ; 
 cout << this->score << endl ;
}
//構(gòu)造函數(shù)的實(shí)現(xiàn) 
Student::Student(char name[],int age , char sex ,int score)
{
 strcpy(this->name,name);
 this->age = age ; 
 this->sex = sex ;
 this->score = score ;
}
//復(fù)制構(gòu)造函數(shù)的實(shí)現(xiàn)
Student::Student(Student &dx)
{
 strcpy(this->name , dx.name);
 this->age = dx.age ; 
 this->sex = dx.sex ;
 this->score = dx.score ;
} 
//析構(gòu)函數(shù)的實(shí)現(xiàn)
Student::~Student()
{
 cout << "程序結(jié)束" << endl ;
} 
int main(void)
{
 Student stu1("YYX",23,'N',86);
 Student stu2(stu1); 
 stu1.disp() ;
 stu2.disp() ;
 return 0 ;
}

運(yùn)行結(jié)果:

YYX
23
N
86
YYX
23
N
86
程序結(jié)束
程序結(jié)束

總結(jié)

以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,謝謝大家對我們的支持。如果你想了解更多相關(guān)內(nèi)容請查看下面相關(guān)鏈接

網(wǎng)頁制作CMS教程網(wǎng)絡(luò)編程軟件編程腳本語言數(shù)據(jù)庫服務(wù)器

如果侵犯了您的權(quán)利,請與我們聯(lián)系,我們將在24小時(shí)內(nèi)進(jìn)行處理、任何非本站因素導(dǎo)致的法律后果,本站均不負(fù)任何責(zé)任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有