// ============================================================================
//  p1c03_34  —  3.10.4 指针引用
//  来源：川大 C++/LinuxC wiki「02.Qt方向」
//  说明：本文件由 gen_part1.py 合并页面中的教学片段而成。每个片段用
//        // --- 原文片段 [pageId:blockIdx] --- 标注出处。
//        已做最小修正（笔误/平台移植），详见 docs/ERRATA.md。
// ============================================================================

#include <iostream>
using namespace std;

// --- 原文片段 [58954439:33]  3.10.4 指针引用 ---
struct Teacher{
	int mAge;
};
//指针间接修改teacher的年龄
void AllocateAndInitByPointer(Teacher** teacher){
	*teacher = (Teacher*)malloc(sizeof(Teacher));
	(*teacher)->mAge = 200;  
}
//引用修改teacher年龄
void AllocateAndInitByReference(Teacher*& teacher){
	teacher->mAge = 300;
}
void test(){
	//创建Teacher
	Teacher* teacher = NULL;
	//指针间接赋值
	AllocateAndInitByPointer(&teacher);
	cout << "AllocateAndInitByPointer:" << teacher->mAge << endl;
	//引用赋值,将teacher本身传到ChangeAgeByReference函数中
	AllocateAndInitByReference(teacher);
	cout << "AllocateAndInitByReference:" << teacher->mAge << endl;
	free(teacher);
}

// --- main ---
int main() {
    test();
    return 0;
}
