이전 질문을 삭제하고 여기에서 질문을 다시 정리하십시오. 대신 템플릿을 사용하여 다음 기능을 수행 할 수 있습니까?MACRO를 사용하지 않고 멤버 변수에 액세스하는 방법
#include <iostream>
using namespace std;
#define FUNC(T1, T2) do {cout<< T1.T2<<endl; } while(0);
struct ST{
double t1;
int t2;
double t3;
};
struct ST2{
int t1;
double h2;
};
int main()
{
ST st;
ST2 st2;
st.t1 = 1.1;
st.t2 = 0;
st.t3 = 3.3;
FUNC(st, t1);
FUNC(st, t2);
FUNC(st, t3);
FUNC(st2, h2);
}
왜 매크로를 사용합니까? –