C/C++语言宏中使用参数做结构体成员

代码:

#include <iostream>

#define MAKE(Object, member, value) ( (Object)-> ## member = (value) )		//宏 

using namespace std;
int main(int argc, char *argv[])
{
	struct student
	{
		int age;
		int score;		
	};
	
	struct student Me;
	struct student *pMe = &Me;
	MAKE(pMe, age,  18);
	MAKE(pMe, score, 99);
	
	cout<<Me.age<<endl;
	cout<<Me.score<<endl;
		
	return 0;
}


©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页