#include <iostream>
class A {
public:
A(int a) : data_(a) {};
private:
int data_ = 0;
};
template <typename PtrType>
struct Access {
inline static PtrType ptr;
};
template <auto V>
struct PtrTaker {
struct Transferer {
Transferer() {
Access<decltype(V)>::ptr = V;
}
};
static Transferer tr;
};
template struct PtrTaker<&A::data_>;
int main() {
A a{10};
std::cout << a.*Access<int A::*>::ptr << std::endl;
return 0;
}
a.*Access<int A::*>::ptr 是如何将a::data_的值或者地址 赋值给Access<int A::*>::ptr
这块没想明白,谢谢
--
FROM 39.155.212.*