auto foo(...) ->decltype(this) 有一些解决方法吗?
auto foo(...) ->decltype(this) Is there some workaround?
我有下一个类,并尝试声明成员函数,该函数将返回指向该类型但下一个代码的指针
template<class Key, int b> class b_plus_tree_inner_node {
auto split() -> decltype(this) {}
};
给我这样的错误
在顶级中无效使用"this"
我可以用另一种方式来做吗?我现在担心typedef的存在,但decltype可能吗?
编辑:
我想完成这个:
b_plus_tree_inner_node<Key, b>* 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(){}
};
如果您想要非成员函数,请将其作为模板:
template<class Key, int b>
b_plus_tree_inner_node<Key, b>* 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 /*...*/;
}
};
相关文章:
- 有没有办法在 c++ 中同时生成随机数?如果没有,是否有解决方法?
- 从 int 中剥离位时,编译器会警告一个转换,但不警告其他转换.有解决方法吗?
- 是否有解决方法可以在 c++ 中为 short 定义用户定义的文字?
- 不为 emplace() 定义构造函数的解决方法
- 删除复制构造函数的 Intel 13.1.2 中不良C++行为的解决方法
- 函数模板部分专业化-有什么解决方法吗
- 带boost的过载模糊性:可选,解决方法
- 继承构造函数和其他变量的解决方法
- C++ 解决方法:"从类型"B*"的表达式初始化类型"C*&"的引用无效"
- 对前向声明类型进行unique_ptr的解决方法
- 解决方法:'can not be used when making a shared object; recompile with -fPIC'使用Cmake。使用普通的 g++ 工作
- 解决方法:QPixmap:在GUI线程之外使用pixmap是不安全的
- CreateProcessWithTokenW 的 cmdline 参数的最大长度是否有解决方法?
- C++双精度作为模板参数的解决方法
- 在参数相关查找之前进行模板替换的任何方法(或解决方法?
- CUDA 内核"Only a single pack parameter is allowed"解决方法?
- dlsym() 解决方法返回类型
- VS2017是否有VLA(可变长度阵列)支持解决方法
- 解决方法:未定义对"class::function"的引用
- 来自 Boost 的 JSON 解析器的警告 C4512 的解决方法