Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/141.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/59.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 自动foo(…)->;decltype(此)是否有一些解决方法?_C++_C++11 - Fatal编程技术网

C++ 自动foo(…)->;decltype(此)是否有一些解决方法?

C++ 自动foo(…)->;decltype(此)是否有一些解决方法?,c++,c++11,C++,C++11,我有了下一个类,并尝试声明成员函数,该函数将返回指向该类型但不是下一个代码的指针 template<class Key, int b> class b_plus_tree_inner_node { auto split() -> decltype(this) {} }; 模板类b\u加上\u树\u内部\u节点{ 自动拆分()->decltype(this){} }; 给了我这样的错误 “this”在顶层的使用无效 我现在想知道typedef的存在,但decltype是否

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

template<class Key, int b> class b_plus_tree_inner_node {
  auto split() -> decltype(this) {}
};
模板类b\u加上\u树\u内部\u节点{
自动拆分()->decltype(this){}
};
给了我这样的错误

“this”在顶层的使用无效

我现在想知道typedef的存在,但decltype是否有可能

编辑:

我想做到这一点:

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

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

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(){}
};
模板类b\u加上\u树\u内部\u节点{
b_plus_tree_inner_node*split(){}
//同样有效的还有:
//b_plus_tree_inner_node*split(){}
};
如果您想要非成员功能,请将其设置为模板:

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

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

您可能希望这样:

template<class Key, int b> 
class b_plus_tree_inner_node 
{        
     b_plus_tree_inner_node<Key, b> split() 
     { 
          return /*...*/;
     }
};
模板
b类加树内节点
{        
b_plus_tree_inner_node split()
{ 
返回/*…*/;
}
};

您真正想要完成什么?如果您想要一个成员函数,为什么要在类外声明它?@R.Martinho Fernandes,typo))我认为“this”在函数的开始大括号之前不在范围内,因此不能成为decltype的一部分。由于“this”是一个伪参数,我觉得这似乎是一个疏忽,但问题仍然存在。请参阅我的‘答案’。“您只能在成员函数体上使用它。”-这不是真的。“this”也可以在“decltype”中的尾部返回类型中使用。这在马德里是一成不变的,所以他的GCC不支持它。由于注入了类名,所以不需要模板参数。注入类名很有趣,我不知道这一点。我想投赞成票。谢谢