回顧day01引用的本質(zhì)
問題:
指針的引用(效果等價(jià)于二級指針)
void getStu_age(Student ** stu){
if(NULL == stu){
return;
}
Student *temp = (Student*)malloc(sizeof(Student));
if(NULL == temp){
return;
}
temp->m_age = 45;
*stu = temp;
return;
}
void getStu_age1(Student* &stu){
stu = (Student*)malloc(sizeof(Student));
if(NULL == stu){
return;
}
stu->m_age = 68;
return;
}
int main(void)
{
Student* student = NULL;
getStu_age1(student);
cout<<student->m_age<<endl;
return 0;
}
常引用:
int x=20;
const int &y = x;//常引用届谈,作用乖菱?
int x=20;
//常引用
const int &y = x;//確保不能通過引用y去修改x
//const int *const y
x=89;
cout<<y<<endl;
問題:
1、int &x=43;error
2、const int &x =43;ok
const int &y = 43;//申請一個(gè)新的空間,用于存儲(chǔ)43這個(gè)數(shù)值淋淀,然后通過y去訪問該空間
3、常引用做函數(shù)參數(shù)的作用覆醇?
4朵纷、const修飾類后面講。
指針和引用的比較
內(nèi)聯(lián)函數(shù)
產(chǎn)生原因:替換宏片段
注意事項(xiàng)結(jié)合課件永脓。
函數(shù)重載
判斷標(biāo)準(zhǔn):函數(shù)名相同袍辞,參數(shù)不同(個(gè)數(shù),類型常摧,順序)搅吁,
返回值不參與判斷
參考課件。
類回顧知識(shí)點(diǎn)
struct和class區(qū)別
struct類型加強(qiáng),默認(rèn)public
class 默認(rèn)private;