我有下一个类,并尝试声明成员函数,它将返回指向该类型但下一个代码的指针
template<class Key, int b> class b_plus_tree_inner_node {
auto split() -> decltype(this) {}
};
Run Code Online (Sandbox Code Playgroud)
给了我这样的错误
在顶层无效使用'this'
我可以用另一种方式做到这一点,我现在关于typedef的存在,但是它可能与decltype有关吗?
编辑:
我想完成这个:
b_plus_tree_inner_node<Key, b>* split() {...}
Run Code Online (Sandbox Code Playgroud)
如果你想要一个成员函数在类中声明它:
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(){}
};
Run Code Online (Sandbox Code Playgroud)
如果您想要非成员函数,请将其设为模板:
template<class Key, int b>
b_plus_tree_inner_node<Key, b>* split(){}
Run Code Online (Sandbox Code Playgroud)
标准允许你写,auto split() -> decltype(this) {}但GCC 4.6还不支持它(GCC 4.7的主干).