1

有什么方法可以安全地将 bsoncxx 文件复制到另一个文件。在下面的代码中,我无法做到这一点

class DocClass
{
private:
    bsoncxx::builder::basic::document m_doc;
public:
    bsoncxx::builder::basic::document& copy(bsoncxx::builder::basic::document& obj)
    {
        obj = m_doc; //Not allowed
        //Error C2280   attempting to reference a deleted function
    }
};

即使复制后也不应该对对象造成任何伤害。请帮忙。

谢谢,世斌

4

1 回答 1

2

如果你想复制一个 bsoncxx::document::value,你可以从它的视图构造一个新的:

bsoncxx::document::value foo = ...;
bsoncxx::document::value bar{foo.view()};

bsoncxx::builder::basic::document 只能移动,不能复制。但是,您可以使用该view()方法从构建器查看基础文档,这可能会根据您的用例为您提供帮助。尽管如此,您仍然只能从构建器中获得一次,因此如果您需要多个,则必须extract依靠构建第二个。document::value

于 2017-08-01T19:32:21.723 回答