gpt4 book ai didi

c++ - boost::filesystem::directory_iterator copy-ctor 隐式删除

转载 作者:太空宇宙 更新时间:2023-11-04 14:19:40 25 4
gpt4 key购买 nike

boost::filesystem::directory_iterator reference (v1.48) 说 directory_iterator 显式定义了一个复制构造函数。我刚看了the code而它并没有,大概是让编译器定义复制构造函数。

是否会发生这样一种情况,即编译器为该类型生成一个移动构造函数,随后发现隐式复制构造函数的格式不正确,从而删除了该复制构造函数?我还没有用简单明了的代码片段重现它,但它似乎是我的代码中正在发生的事情,带有 2011 年 12 月 17 日的 gcc 4.7 快照。不过我在 gcc 4.6.1 中没有这个问题。

下面是 gcc 4.7 的错误提示:

In file included from /usr/local/include/boost/iterator/interoperable.hpp:13:0,
from /usr/local/include/boost/iterator/iterator_facade.hpp:11,
from /usr/local/include/boost/filesystem/v3/path.hpp:28,
from /usr/local/include/boost/filesystem/path.hpp:31,
from /Users/matan/Development/ouch.git/src/include/ouch/operations.hh:4,
from /Users/matan/Development/ouch.git/src/libouch/operations.cc:1:
/usr/local/include/boost/type_traits/is_convertible.hpp: In instantiation of 'const bool boost::detail::is_convertible_basic_impl<boost::filesystem3::directory_iterator&, boost::filesystem3::directory_iterator>::value':
/usr/local/include/boost/type_traits/is_convertible.hpp:296:272: required from 'const bool boost::detail::is_convertible_impl<boost::filesystem3::directory_iterator, boost::filesystem3::directory_iterator>::value'
/usr/local/include/boost/type_traits/is_convertible.hpp:419:47: required from 'struct boost::is_convertible<boost::filesystem3::directory_iterator, boost::filesystem3::directory_iterator>'
/usr/local/include/boost/mpl/aux_/nested_type_wknd.hpp:26:31: required from 'struct boost::mpl::aux::nested_type_wknd<boost::is_convertible<boost::filesystem3::directory_iterator, boost::filesystem3::directory_iterator> >'
/usr/local/include/boost/mpl/aux_/preprocessed/gcc/or.hpp:48:8: required from 'struct boost::mpl::or_<boost::is_convertible<boost::filesystem3::directory_iterator, boost::filesystem3::directory_iterator>, boost::is_convertible<boost::filesystem3::directory_iterator, boost::filesystem3::directory_iterator>, mpl_::bool_<false>, mpl_::bool_<false>, mpl_::bool_<false> >'
/usr/local/include/boost/iterator/detail/enable_if.hpp:68:12: required from 'struct boost::iterators::enable_if<boost::mpl::or_<boost::is_convertible<boost::filesystem3::directory_iterator, boost::filesystem3::directory_iterator>, boost::is_convertible<boost::filesystem3::directory_iterator, boost::filesystem3::directory_iterator>, mpl_::bool_<false>, mpl_::bool_<false>, mpl_::bool_<false> >, bool>'
/usr/local/include/boost/iterator/iterator_facade.hpp:67:12: required from 'struct boost::detail::enable_if_interoperable<boost::filesystem3::directory_iterator, boost::filesystem3::directory_iterator, bool>'
/usr/local/include/boost/iterator/iterator_facade.hpp:837:323: required by substitution of 'template<class Derived1, class V1, class TC1, class Reference1, class Difference1, class Derived2, class V2, class TC2, class Reference2, class Difference2> typename boost::detail::enable_if_interoperable<Derived1, Derived2, typename boost::mpl::apply2<boost::detail::always_bool2, Derived1, Derived2>::type>::type boost::operator!=(const boost::iterator_facade<Derived1, V1, TC1, Reference1, Difference1>&, const boost::iterator_facade<Derived2, V2, TC2, Reference2, Difference2>&) [with Derived1 = boost::filesystem3::directory_iterator; V1 = boost::filesystem3::directory_entry; TC1 = boost::single_pass_traversal_tag; Reference1 = boost::filesystem3::directory_entry&; Difference1 = long int; Derived2 = boost::filesystem3::directory_iterator; V2 = boost::filesystem3::directory_entry; TC2 = boost::single_pass_traversal_tag; Reference2 = boost::filesystem3::directory_entry&; Difference2 = long int]'
/usr/local/include/boost/filesystem/v3/operations.hpp:691:49: required from here
/usr/local/include/boost/type_traits/is_convertible.hpp:137:49: error: use of deleted function 'boost::filesystem3::directory_iterator::directory_iterator(const boost::filesystem3::directory_iterator&)'
In file included from /usr/local/include/boost/filesystem/operations.hpp:31:0,
from /Users/matan/Development/ouch.git/src/libouch/operations.cc:4:
/usr/local/include/boost/filesystem/v3/operations.hpp:581:9: note: 'boost::filesystem3::directory_iterator::directory_iterator(const boost::filesystem3::directory_iterator&)' is implicitly deleted because the default definition would be ill-formed:
/usr/local/include/boost/filesystem/v3/operations.hpp:581:9: error: use of deleted function 'boost::shared_ptr<boost::filesystem3::detail::dir_itr_imp>::shared_ptr(const boost::shared_ptr<boost::filesystem3::detail::dir_itr_imp>&)'

最佳答案

是的,一个类型可以很容易地移动但不可复制。例如,如果它有一个不可复制但可移动的成员或基类。在 C++11 中,它可能是一个 std::fstream。

在这种情况下,编译器可以为您的类创建一个移动构造函数,但会将复制构造函数声明为已删除。

关于c++ - boost::filesystem::directory_iterator copy-ctor 隐式删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8611639/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com