"非静态数据成员之前需要构造函数" - 我是否使用"boost::variant"
`constructor required before non-static data member` - Am I hitting c++ core issue 1360 with a `boost::variant`?
使用此代码
#include <boost/variant.hpp>
#include <string>
struct Outer
{
struct StateA
{
std::size_t index = std::string::npos;
};
struct StateB {};
using State = boost::variant<StateA, StateB>;
struct Inner
{
State state = StateB{};
};
};
int main() {
Outer o;
(void)o;
}
我收到以下编译错误
/usr/include/boost/variant/variant.hpp:1301:17: required from ‘class boost::variant<Outer::StateA, Outer::StateB>’
inner_class.cpp:18:30: required from here
/usr/include/boost/type_traits/has_nothrow_constructor.hpp:27:84: error: constructor required before non-static data member for ‘Outer::StateA::index’ has been parsed
template <class T> struct has_nothrow_constructor : public integral_constant<bool, BOOST_HAS_NOTHROW_CONSTRUCTOR(T)>{};
提到这个问题,我似乎遇到了这个核心问题,但我想检查一下我的理解。
具体来说,我是否击中了
当前文本中未指定的顺序依赖关系
当我的variant
typedef
在Inner
中初始化时? 还是内部struct
还有其他原因导致此编译错误?
这不依赖于(发现(constexpr
任何东西,所以它与CWG1360不同,但它肯定是相似的,因为它利用了不可能同时让嵌套类成为其包含类的完整类上下文,并且嵌套类在包含类中比其定义更晚完成。 也许最好的轨迹是CWG2335,为此已经提出了一般(长期(建议,即类中的实际依赖关系应该通过类似实例化的机制进行跟踪;像你这样的例子要求跨班级进行这样的处理。
相关文章:
- 在提升multi_index容器中,是否定义了"default index"?
- 在C++STL中是否有Polyval(Matlab函数)等价物?
- 检查输入是否不是整数或数字
- 是否可以初始化不可复制类型的成员变量(或基类)
- 在C++中,是否可以基于给定的标识符创建基类的新实例,反之亦然
- 是否可以通过C++扩展强制多个python进程共享同一内存
- 此代码是否违反一个定义规则
- 是否需要删除包含对象的"pair"?
- 是否可以从int转换为enum类类型
- 无论条件是否为true,if总是在c++中执行
- 如何找到大小'x'数组是否完全填充,在C++?
- 检查值是否在集合p1和p2中,但不在p3中
- 是否可以在编译时初始化数组,以便在运行时不会花费时间?
- 检查 std::shared_ptr<> 的当前底层类型是否为 T
- 在c++中检查长方体是否尽可能快地重叠(无迭代)
- GL_SHADERSTORAGE_BUFFER位置是否与其他着色器位置冲突
- 子目录是否继承属性,例如add_definitions,include_directories和父Cmakelist.t
- 标准是否使用多余的大括号(例如 T{{{10}}})定义列表初始化?
- C/C++预处理器是否可以检测一些编译器选项
- "非静态数据成员之前需要构造函数" - 我是否使用"boost::variant"