#include
class CPrivate
{
int setAge(int age)
{
std::swap(age, this->age);
return age;
}
int age{ 123 };
};
template
struct CTest
{
friend int getAge(Obj& obj)
{
return (obj.*age);
}
friend int setAgeFun(Obj &obj, int age)
{
return (obj.*setAge)(age);
}
};
template CTest;
int getAge(CPrivate& test);
int setAgeFun(CPrivate &test, int age);
int main()
{
CPrivate test;
std::cout << getAge(test) << std::endl;
std::cout << setAgeFun(test, 256) << std::endl;
std::cout << getAge(test) << std::endl;
return 0;
}
总结: