【发布时间】:2025-12-29 18:10:15
【问题描述】:
为什么这段代码会编译?
std::shared_ptr<const int> Bar()
{
return std::make_shared<int>(123);
}
但这并不...
boost::optional<const int> Foo()
{
return boost::optional<int>(123);
}
我收到以下错误:
无法将 'boost::optional
(123)' 从 'optional ' 转换为 '可选 '
使用 gcc 6.3.0 和 boost 1.65.1。
【问题讨论】:
-
值得注意的是,这适用于
std::optional -
boost::optional<T const>一开始似乎不是很有用。这有点像从函数 (T const foo()) 或例如返回T const事实上void bar(int);和void bar(int const);是完全相同的函数声明。