指针应用
struct Teacher
{
int age;
};
void test()
{
Teacher* teacher = NULL;
teacher = (Teacher*)malloc(sizeof(Teacher));
Teacher*& ref = teacher;
ref->age = 30;
std::cout << teacher->age << std::endl;
free(ref);
}
常量引用
void test1()
{
int a = 100;
const int& ref = a;
//ref = 200;错误,不能赋值
a = 200;
std::cout << a << std::endl;
}