自动foo(...)-> decltype(this)有一些解决方法吗? [英] auto foo(...) ->decltype(this) Is there some workaround?

查看:74
本文介绍了自动foo(...)-> decltype(this)有一些解决方法吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有下一个类,并尝试声明成员函数,该函数将返回指向该类型但下一个代码的指针

I have next class and try to declare member function which will return pointer to a that type but next code

template<class Key, int b> class b_plus_tree_inner_node {
  auto split() -> decltype(this) {}
};

给我这样的错误


在顶层无效使用'this'

invalid use of ‘this’ at top level

我可以用另一种方式做到这一点吗,我现在谈到typedef,但使用decltype可能吗?

can i do it in another way, i now about existence of typedef, but may be its possible with decltype?

已编辑:

我想完成此操作:

b_plus_tree_inner_node<Key, b>* split() {...}


推荐答案

如果需要成员函数,请在类中声明它:

If you want a member function declare it inside the class:

template<class Key, int b> class b_plus_tree_inner_node {
   b_plus_tree_inner_node* split(){}
   // also valid:
   //b_plus_tree_inner_node<Key, b>* split(){}
};

如果要使用非成员函数,请将其作为模板:

If you want a non-member function, make it a template:

template<class Key, int b>
b_plus_tree_inner_node<Key, b>* split(){}

该标准确实允许您编写 auto split()-> decltype(this){} ,但GCC 4.6尚不支持(GCC 4.7的主干支持)。

The standard does allow you to write auto split() -> decltype(this) {} but GCC 4.6 doesn't support it yet (the trunk of GCC 4.7 does).

这篇关于自动foo(...)-&gt; decltype(this)有一些解决方法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆