pae*_*bal 6 c++ auto-ptr c++11 c++98
以下代码不能在Visual C++ 2008和2010上编译:
#include <memory>
struct A {};
std::auto_ptr<A> foo() { return std::auto_ptr<A>(new A); }
const std::auto_ptr<A> bar() { return std::auto_ptr<A>(new A); }
int main()
{
const std::auto_ptr<A> & a = foo(); // most important const
const std::auto_ptr<A> & b = bar(); // error C2558:
// class 'std::auto_ptr<_Ty>' :
// no copy constructor available or copy
// constructor is declared 'explicit'
bar(); // No error?
}
Run Code Online (Sandbox Code Playgroud)
我期望"最重要的const"应用于变量"b",然而,它不会编译,并且由于某种原因,编译器要求复制构造函数(这让我感到惊讶,因为这里不应该涉及复制) .独立调用bar()工作正常,这意味着,我猜,它实际上是初始化b的问题.
这是编译器错误,还是标准中描述的真正的编译错误?
(也许它在C++ 98中被禁止并在C++ 11中被授权?)
注意:它在Visual C++ 2012,gcc 4.6和Solaris CC(所有编译器......)上编译,但不是gcc 3.4,也不是XL C)
| 归档时间: |
|
| 查看次数: |
358 次 |
| 最近记录: |