如何声明 noexcept 如果只有属性的成员函数是 noexcept
How to declare noexcept if only a member function of an attribute is noexcept?
#include <vector>
class A
{
std::vector<int> vec;
void swap( A & other) noexcept(noexcept(vec.swap(other.vec)))
{
vec.swap(other.vec);
}
};
int main()
{
}
这段代码在 clang(3.4) 下编译,但不在 gcc (4.7.1) 下编译。谁能告诉我我做错了什么?
编辑
GCC 错误消息是 :
error: invalid use of incomplete type ‘class A’
error: forward declaration of ‘class A’
作为解决方法,您可以使用(适用于 gcc 4.7.1、gcc 4.8.1 和 clang 3.4):
void swap(A& other) noexcept(noexcept(std::declval<decltype(A::vec)&>().swap(std::declval<decltype(A::vec)&>())))
或
void swap(A& other) noexcept(noexcept(vec.swap(vec)))
我认为问题other.vec
...
相关文章:
- 如何导出包含具有"std::unique_ptr"值的"std::map"属性的
- C++概念:如何使用'concept'检查模板化结构的属性?
- 子目录是否继承属性,例如add_definitions,include_directories和父Cmakelist.t
- 通过指向指针数组的指针访问子类的属性
- MSVC是否支持C++11样式的属性而不是__declspec
- QML:修改在不同QML文件(而非main.QML)中定义的子对象的属性
- 类的C++属性似乎已重新初始化
- Qt Quick-如何仅从c++代码与qml属性交互
- 用概念检查属性的类型
- C++如何将同一类的实例作为属性
- 在noexcept 规范中是否允许使用"this"?
- 按多个属性排序
- 主函数参数的属性
- "perf_event_attr"结构的"read_format"属性的选项到底是什么?
- C++删除未使用的类属性会导致 std::logic_error
- 无法使用 SWIG 在 Python 中实例化C++类(获取属性错误)
- 使用内存地址访问结构的属性值
- 使用 noexcept 运算符 depenendet
- 不同编译器中的STD容器的不同NOExcept属性
- 如何声明 noexcept 如果只有属性的成员函数是 noexcept