#include<iostream>
template<typename T>
struct invisible
{
static typename T::type value;
};
template<typename T>
typename T::type invisible<T>::value;
//////////////////////////////////////////////////////////////////////////
template<typename T, typename T::type P>
class construct_invisible
{
construct_invisible(){ invisible<T>::value = P; }
static const construct_invisible instance;
};
template<typename T, typename T::type P>
const construct_invisible<T, P> construct_invisible<T, P>::instance;
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
class A
{
public:
A(int x) : m_X(x){}
private:
int m_X;
};
//////////////////////////////////////////////////////////////////////////
struct A_x{ typedef int A::*type; };
template class construct_invisible<A_x, &A::m_X>;// <---- WHY DOES `&A::m_X` WORK HERE?
//////////////////////////////////////////////////////////////////////////
int main()
{
A a(17);
std::cout << a.*invisible<A_x>::value << '\n';
}
I2luY2x1ZGU8aW9zdHJlYW0+Cgp0ZW1wbGF0ZTx0eXBlbmFtZSBUPgpzdHJ1Y3QgaW52aXNpYmxlCnsKICAgIHN0YXRpYyB0eXBlbmFtZSBUOjp0eXBlIHZhbHVlOwp9OwoKdGVtcGxhdGU8dHlwZW5hbWUgVD4KdHlwZW5hbWUgVDo6dHlwZSBpbnZpc2libGU8VD46OnZhbHVlOwoKLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8KdGVtcGxhdGU8dHlwZW5hbWUgVCwgdHlwZW5hbWUgVDo6dHlwZSBQPgpjbGFzcyBjb25zdHJ1Y3RfaW52aXNpYmxlCnsKICAgIGNvbnN0cnVjdF9pbnZpc2libGUoKXsgaW52aXNpYmxlPFQ+Ojp2YWx1ZSA9IFA7IH0KICAgIHN0YXRpYyBjb25zdCBjb25zdHJ1Y3RfaW52aXNpYmxlIGluc3RhbmNlOwp9OwoKdGVtcGxhdGU8dHlwZW5hbWUgVCwgdHlwZW5hbWUgVDo6dHlwZSBQPgpjb25zdCBjb25zdHJ1Y3RfaW52aXNpYmxlPFQ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