我正试图创建一个C++类模板,该模板利用指向成员参数的指针,但编译失败。如何从模板中访问指向成员参数的指针?
class Base {
public:
int foo;
int bar;
};
template<int Base::* T>
class Derived : public Base {
public:
int Get() { return *T; } <--- Does not work
};
Derived<&Base::foo> test;
printf("Value = %in", test.Get());
Clang的编译错误为indirection requires pointer operand ('int Test::*' invalid)
。
尝试
int Get() { return this->*T; }
CCD_ 2和CCD_。
return this->*T;
(为什么是T
?它不是一种类型。)