运算符 = 不明确 (C++)
我在 for 循环中有以下内容,编译器说“运算符 = 不明确”。不知道如何解决这个问题,有人可以帮忙吗?
rootelement = document->getDocumentElement();
boost::interprocess::unique_ptr<DOMNodeIterator, release_deleter> itera (document->createNodeIterator(rootelement, DOMNodeFilter::SHOW_ALL, NULL, true));
for(boost::interprocess::unique_ptr<DOMNode, release_deleter> current (itera->nextNode()); current != 0; current = boost::interprocess::unique_ptr<DOMNode, release_deleter> (itera->nextNode())) // Last assignment on current is ambiguous
完整错误
**
\XMLDocument.cpp(193) : error C2593: 'operator =' is ambiguous
c:\Program Files\boost\boost_1_44\boost\interprocess\smart_ptr\unique_ptr.hpp(249): could be 'boost::interprocess::unique_ptr<T,D> &boost::interprocess::unique_ptr<T,D>::operator =(int boost::interprocess::unique_ptr<T,D>::nat::* )'
with
[
T=xercesc_3_1::DOMNode,
D=release_deleter
]
unique_ptr.hpp(211): or 'boost::interprocess::unique_ptr<T,D> &boost::interprocess::unique_ptr<T,D>::operator =(boost::interprocess::rv<boost::interprocess::unique_ptr<T,D>> &)'
with
[
T=xercesc_3_1::DOMNode,
D=release_deleter
]
while trying to match the argument list '(boost::interprocess::unique_ptr<T,D>, boost::interprocess::unique_ptr<T,D>)'
with
[
T=xercesc_3_1::DOMNode,
D=release_deleter
]
and
[
T=xercesc_3_1::DOMNode,
D=release_deleter
]
\XMLDocument.cpp(193) : see reference to class template instantiation 'boost::interprocess::detail::unique_ptr_error<T>' being compiled
with
[
T=boost::interprocess::unique_ptr<xercesc_3_1::DOMNode,release_deleter>
]
XMLDocument.cpp(193) : see reference to class template instantiation 'boost::interprocess::detail::unique_ptr_error<T>' being compiled
with
[
T=xercesc_3_1::DOMNode *
]
\XMLDocument.cpp(193) : see reference to class template instantiation 'boost::interprocess::detail::unique_ptr_error<T>' being compiled
with
[
T=xercesc_3_1::DOMNode *
]
XMLDocument.cpp(192) : see reference to class template instantiation 'boost::int
erprocess::detail::unique_ptr_error<T>' being compiled
with
[
T=xercesc_3_1::DOMNodeIterator *
]
:
I have the following in a for loop and the compiler says 'operator = is ambiguous'. Not sure how to solve this issue, can anyone help?
rootelement = document->getDocumentElement();
boost::interprocess::unique_ptr<DOMNodeIterator, release_deleter> itera (document->createNodeIterator(rootelement, DOMNodeFilter::SHOW_ALL, NULL, true));
for(boost::interprocess::unique_ptr<DOMNode, release_deleter> current (itera->nextNode()); current != 0; current = boost::interprocess::unique_ptr<DOMNode, release_deleter> (itera->nextNode())) // Last assignment on current is ambiguous
Full error:
*
\XMLDocument.cpp(193) : error C2593: 'operator =' is ambiguous
c:\Program Files\boost\boost_1_44\boost\interprocess\smart_ptr\unique_ptr.hpp(249): could be 'boost::interprocess::unique_ptr<T,D> &boost::interprocess::unique_ptr<T,D>::operator =(int boost::interprocess::unique_ptr<T,D>::nat::* )'
with
[
T=xercesc_3_1::DOMNode,
D=release_deleter
]
unique_ptr.hpp(211): or 'boost::interprocess::unique_ptr<T,D> &boost::interprocess::unique_ptr<T,D>::operator =(boost::interprocess::rv<boost::interprocess::unique_ptr<T,D>> &)'
with
[
T=xercesc_3_1::DOMNode,
D=release_deleter
]
while trying to match the argument list '(boost::interprocess::unique_ptr<T,D>, boost::interprocess::unique_ptr<T,D>)'
with
[
T=xercesc_3_1::DOMNode,
D=release_deleter
]
and
[
T=xercesc_3_1::DOMNode,
D=release_deleter
]
\XMLDocument.cpp(193) : see reference to class template instantiation 'boost::interprocess::detail::unique_ptr_error<T>' being compiled
with
[
T=boost::interprocess::unique_ptr<xercesc_3_1::DOMNode,release_deleter>
]
XMLDocument.cpp(193) : see reference to class template instantiation 'boost::interprocess::detail::unique_ptr_error<T>' being compiled
with
[
T=xercesc_3_1::DOMNode *
]
\XMLDocument.cpp(193) : see reference to class template instantiation 'boost::interprocess::detail::unique_ptr_error<T>' being compiled
with
[
T=xercesc_3_1::DOMNode *
]
XMLDocument.cpp(192) : see reference to class template instantiation 'boost::int
erprocess::detail::unique_ptr_error<T>' being compiled
with
[
T=xercesc_3_1::DOMNodeIterator *
]
*
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为 std::unique_ptr 只能通过调用 std::move() 来分配。
这是它明确失去底层对象所有权的方式。
正如 GMan 所说,C++0x 还不是当前的 C++ 标准,所以它应该是
boost::进程间::unique_ptr...
I think a std::unique_ptr can only be assigned with a call to std::move().
This is the way it explicitely loses the ownership of the underlying object.
As GMan has remarked, C++0x is not yet the current C++ standard, so it should be
boost::interprocess::unique_ptr...
我不确定,也没有尝试过任何东西,但你可以尝试:
那么它只需要其中一个歧义。
I'm not sure, and haven't tried anything, but you can try:
Then it will take only one of the ambiguities.
就像 Stephane 所说,unique_ptr 保持唯一性,除非您显式移动它们,或为它们分配右值。通常,您的代码没问题,但由于您伪造了右值,因此您需要显式地移动它。
我从未使用过 boost::interprocess::unique_ptr,但看起来您想要这样:
更简单的可能是:
Like Stephane says,
unique_ptr
's maintain uniqueness unless you explicitly move them, or assign an rvalue to them. Normally, your code would be fine, but since you're faking rvalues, you'll need to move it explicitly.I've never used
boost::interprocess::unique_ptr
, but it looks like you want this:Simpler might be: