为什么这不起作用?
struct O {
O(int i, int j)
: i(i)
, j(j)
{}
int const i;
int const j;
};
int main(int argc, char** argv)
{
boost::optional<O> i;
i.reset(O(4, 5));
return 0;
}
它似乎是在尝试使用赋值运算符,而不是尝试在适当的位置构造它。我曾假设它会在未初始化的内存上调用 O 的复制构造函数。
/..../include/boost/optional/optional.hpp:433:69: error: use of deleted function ‘O& O::operator=(const O&)’
.... error: ‘O& O::operator=(const O&)’ is implicitly deleted because the default definition would be ill-formed:
.... error: non-static const member ‘const int O::i’, can’t use default assignment operator
.... error: non-static const member ‘const int O::j’, can’t use default assignment operator