【发布时间】:2017-01-02 12:22:01
【问题描述】:
我有一些类 C 与 const 和非 const 一些泛型类型 Node 的吸气剂:
template <typename NodeType>
class CParent{};
class Node {};
class C : public CParent<Node> {
Node& getNode(Index i);
const Node& getNode(Index i) const;
};
现在我想创建一个别名函数,为 C 类的对象调用 getNode:
template <class CType>
NodeType& AliasGetNode(CType* cobject);
但是我如何推断NodeType?也就是说,如果我打电话给AliasGetNode<const C>(c)和AliasGetNode<C>(c),NodeType应该分别是const Node&和Node&。
我该怎么做?
我尝试了result_of 和decltype 方法,但没有成功。
【问题讨论】:
-
I tried the result_of and decltype approaches but have not been successful.您应该发布您尝试过的什么,以及发生了什么。只是对事物进行模糊的暗示并说它们不起作用是没有用的。我的意思是,我猜你刚刚收到了 49 屏模板错误,但如果能确定一下就好了! -
@underscore_d 是肯定的。但是在这种情况下,由于我希望解决方案很简单,所以我试图避免 49 屏幕的混乱。另外,关于
result_of和decltype主题有很多具体问题没有专门解决我的问题,我会得到一个错误的“重复”问题标记