如何访问指向C++类模板中成员参数的指针
How to access pointer to member parameter in C++ class template?
我正试图创建一个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
?它不是一种类型。)
相关文章:
- 基于另一个成员参数将函数调用从类传递给它的一个成员
- 使用指向成员的指针将成员函数作为参数传递
- 如何将lambda作为模板类的成员函数参数
- 将成员函数指针作为参数传递给模板方法
- c++构造函数成员初始化:传递参数
- 使用带有 ref 参数的成员函数创建线程时出现编译错误
- 如何将成员函数作为回调参数传递给需要"typedef-ed"自由函数指针的函数?
- 模板化检查是否存在带有参数列表的类成员函数?
- 如何将类成员方法的参数列表自动填充写入可变参数?
- 为什么我需要在成员发起器列表中重复基类的模板参数?
- C++向量默认为成员参数
- 将成员函数作为构造函数参数调用时出错 "Variable is not a type name"
- 可变参数模板参数扩展 类型为 std::function 的类成员
- 当类成员参数具有相同的名称时,如何定义构造函数?
- 类成员参数中的Constexpr
- 允许通过指向方法的成员参数的指针来推断模板参数所指向的成员类型
- 为什么未调用的模板类成员 *参数* 被实例化
- 如何访问指向C++类模板中成员参数的指针
- 我们是否需要在嵌套类型的成员参数前面加上"::"?
- 设计模式- c++运行时成员参数的实例化