auto_ptr无法正常工作 - 编译错误

Art*_*amz 3 c++ auto-ptr qnx


大规模编辑:

在juanchopanza建议之后,我设法得到了这个最小的例子:

#include <memory>

struct a{
    int b;
};

int main()
{

    typedef std::auto_ptr<a> ArgAutoPtr;

    ArgAutoPtr floatingArg;

    floatingArg = ArgAutoPtr( new a );

}
Run Code Online (Sandbox Code Playgroud)

这给了我错误:

no match for 'operator=' in 'm_floatingArg = std::auto_ptr<a>(((a*)operator new(4u)))'
Run Code Online (Sandbox Code Playgroud)

QNX 6.4.1与GCC 4.3.3

编辑

我设法像这样编译它.这是否按预期工作或将产生......无论邪恶auto_ptr产生什么?

ArgAutoPtr floatingArg2 = ArgAutoPtr( new a );
floatingArg = floatingArg2;
Run Code Online (Sandbox Code Playgroud)

Mar*_*som 6

表达式ArgAutoPtr( new a )正在创建一个临时的auto_ptr.

auto_ptr::operator=对其参数采用非const引用,与其他所有示例不同operator=.非const引用不能绑定到临时引用.