我有下一个类,并尝试声明成员函数,它将返回指向该类型的指针,但返回下一个代码。
template<class Key, int b> class b_plus_tree_inner_node {
auto split() -> decltype(this) {}
};给了我这样的错误
在顶层使用“this”无效
我可以用另一种方式来做吗,我现在是关于类型胡枝子的存在,但是它可能有解密的可能吗?
编辑:
我想要做到这一点:
b_plus_tree_inner_node<Key, b>* split() {...}发布于 2012-01-17 09:27:51
如果您想要一个成员函数,在类中声明它:
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(){}
};如果您想要一个非会员函数,请让它成为一个模板:
template<class Key, int b>
b_plus_tree_inner_node<Key, b>* split(){}这个标准确实允许你编写auto split() -> decltype(this) {},但是GCC 4.6还不支持它( GCC 4.7的主干)。
发布于 2012-01-17 09:28:28
你可能想要这个:
template<class Key, int b>
class b_plus_tree_inner_node
{
b_plus_tree_inner_node<Key, b> split()
{
return /*...*/;
}
};https://stackoverflow.com/questions/8892083
复制相似问题