获取模板化模板类型
Get templated, template type
我正在创建一个小型的'通用'寻路类,该类采用类类型的Board
,它将在其上查找路径,
//T - Board class type
template<class T>
class PathFinder
{...}
而Board
也被模板化以保存节点类型。(这样我就可以在 2D 或 3D 向量空间上找到路径)。
我希望能够为PathFinder
声明和定义一个成员函数,该函数将采用这样的参数
//T - Board class type
PathFinder<T>::getPath( nodeType from, nodeType to);
如何对作为参数馈送到函数中的T
和nodeType
的节点类型执行类型兼容性?
如果我
明白你想要什么,给board
一个类型成员并使用它:
template<class nodeType>
class board {
public:
typedef nodeType node_type;
// ...
};
PathFinder<T>::getPath(typename T::node_type from, typename T::node_type to);
如果您无法更改board
,您也可以进行模式匹配:
template<class Board>
struct get_node_type;
template<class T>
struct get_node_type<board<T> > {
typedef T type;
};
PathFinder<T>::getPath(typename get_node_type<T>::type from, typename get_node_type<T>::type to);
您可以在类定义中typedef
nodeType
:
typedef typename T::nodeType TNode;
PathFinder<T>::getPath( TNode from, TNode to);
相关文章:
- 如何获取std::result_of函数的返回类型
- 有没有办法通过使用十进制 ASCII 代码自动类型扣除来获取字符?
- 如何获取C++字符数据类型的地址
- C++ - 声明指向返回任何类型并获取任意数量参数的函数的指针
- 如何在没有实例的情况下获取非静态方法的类型?
- 获取 OID(类型::b_oid)作为 MongoDB C++驱动程序中的字符串
- 数组中不同类型的对象并获取每个对象的类型
- 获取可变参数模板参数包的相关类型
- 我可以使用 decltype() 或其他东西通过指针获取真实类型吗?
- 从组件的 std::type_index 获取派生最多的类型
- 在 std::variant 中按类型获取索引
- Cython:如何从C级类型获取'actual Python type'(类型代码/dtype)
- 根据参数类型获取匹配过载
- 编译按映射类型获取元素的映射错误元组
- 将 lambda 参数类型获取到模板参数包中
- 按类型获取元组元素(pre C++0x)
- std::array<T,N> 需要以另一种类型获取
- std::tuple,按继承类型获取项
- Boost变体:根据其类型获取对变体的引用
- 从双精度数据类型获取特定整数的方法