回顾day01引用的本质
问题:
指针的引用(效果等价于二级指针)
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;//申请一个新的空间,用于存储43这个数值,然后通过y去访问该空间
3、常引用做函数参数的作用?
4、const修饰类后面讲。
指针和引用的比较
内联函数
产生原因:替换宏片段
注意事项结合课件。
函数重载
判断标准:函数名相同,参数不同(个数,类型,顺序),
返回值不参与判断
参考课件。
类回顾知识点
struct和class区别
struct类型加强,默认public
class 默认private;