shared_ptr.hpp(321) : error C2039: 'type_info' : is not a member of 'std' 错误修正

本文解决在VC++6.0环境下使用Boost库中的shared_ptr时遇到的编译错误,具体为找不到std::type_info的问题。通过调整代码使其正常编译。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

vc++ 6.0使用boost::shared_ptr(boost版本boost_1_33_1)出现以下错误:

f:/c++/boost_1_33_1/boost/shared_ptr.hpp(321) : error C2039: 'type_info' : is not a member of 'std'
        f:/c++/boost_1_33_1/boost/shared_ptr.hpp(342) : see reference to class template instantiation 'boost::shared_ptr<T>' being compiled
f:/c++/boost_1_33_1/boost/shared_ptr.hpp(321) : error C2039: 'type_info' : is not a member of 'std'
        c:/program files/microsoft visual studio/vc98/include/utility(26) : see reference to class template instantiation 'boost::shared_ptr<class PersistentObject>' being compiled
        c:/program files/microsoft visual studio/vc98/include/xtree(28) : see reference to class template instantiation 'std::pair<class Key const ,class boost::shared_ptr<class PersistentObject> >' being compiled
        c:/program files/microsoft visual studio/vc98/include/map(46) : see reference to class template instantiation 'std::_Tree<class Key,struct std::pair<class Key const ,class boost::shared_ptr<class PersistentObject> >,struct std::map<class Key
,class boost::shared_ptr<class PersistentObject>,struct std::less<class Key>,class std::allocator<class boost::shared_ptr<class PersistentObject> > >::_Kfn,struct std::less<class Key>,class std::allocator<class boost::shared_ptr<class PersistentObje
ct> > >' being compiled
        f:/vc6/tinyorm/orm/abstractmapper.h(96) : see reference to class template instantiation 'std::map<class Key,class boost::shared_ptr<class PersistentObject>,struct std::less<class Key>,class std::allocator<class boost::shared_ptr<class Persis
tentObject> > >' being compiled
PersistentCriteria.cpp
f:/c++/boost_1_33_1/boost/shared_ptr.hpp(321) : error C2039: 'type_info' : is not a member of 'std'
        f:/c++/boost_1_33_1/boost/shared_ptr.hpp(342) : see reference to class template instantiation 'boost::shared_ptr<T>' being compiled
f:/c++/boost_1_33_1/boost/shared_ptr.hpp(321) : error C2039: 'type_info' : is not a member of 'std'
        c:/program files/microsoft visual studio/vc98/include/utility(26) : see reference to class template instantiation 'boost::shared_ptr<class PersistentObject>' being compiled
        c:/program files/microsoft visual studio/vc98/include/xtree(28) : see reference to class template instantiation 'std::pair<class Key const ,class boost::shared_ptr<class PersistentObject> >' being compiled
        c:/program files/microsoft visual studio/vc98/include/map(46) : see reference to class template instantiation 'std::_Tree<class Key,struct std::pair<class Key const ,class boost::shared_ptr<class PersistentObject> >,struct std::map<class Key
,class boost::shared_ptr<class PersistentObject>,struct std::less<class Key>,class std::allocator<class boost::shared_ptr<class PersistentObject> > >::_Kfn,struct std::less<class Key>,class std::allocator<class boost::shared_ptr<class PersistentObje
ct> > >' being compiled
        f:/vc6/tinyorm/orm/abstractmapper.h(96) : see reference to class template instantiation 'std::map<class Key,class boost::shared_ptr<class PersistentObject>,struct std::less<class Key>,class std::allocator<class boost::shared_ptr<class Persis
tentObject> > >' being compiled
PersistentObject.cpp

 

 

跟踪发现,原来错误的代码出现在(红色处):

 

void * _internal_get_deleter(std::type_info const & ti) const
    {
        return pn.get_deleter(ti);
    }

 

将代码中的 std::一一 去掉后(搜索一下,有好几处),居然编译通过。

 

 

分析原因:

         type_info 为运行时类型识别功能提供支持,vc++6.0 环境中自带了TYPEINFO.H头文件(在路径C:/Program Files/Microsoft Visual Studio/VC98/Include下),而该文件中定义的class type_info 并不在std 的namespace中。

 

 

 

In file included from /home/xkf/opencv-4.5.5/build/3rdparty/ade/ade-0.1.1f/sources/ade/include/ade/passes/topological_sort.hpp:17, from /home/xkf/opencv-4.5.5/build/3rdparty/ade/ade-0.1.1f/sources/ade/source/topological_sort.cpp:7: /home/xkf/opencv-4.5.5/build/3rdparty/ade/ade-0.1.1f/sources/ade/include/ade/typed_graph.hpp:101:10: error: ‘uintptr_t’ in namespace ‘std’ does not name a type 101 | std::uintptr_t m_srcGraph; | ^~~~~~~~~ /home/xkf/opencv-4.5.5/build/3rdparty/ade/ade-0.1.1f/sources/ade/include/ade/typed_graph.hpp:22:1: note: ‘std::uintptr_t’ is defined in header ‘<cstdint>’; did you forget to ‘#include <cstdint>’? 21 | #include "typed_metadata.hpp" +++ |+#include <cstdint> 22 | /home/xkf/opencv-4.5.5/build/3rdparty/ade/ade-0.1.1f/sources/ade/include/ade/typed_graph.hpp: In member function ‘const ade::Graph& ade::ConstTypedGraph<Types>::getCGraph() const’: /home/xkf/opencv-4.5.5/build/3rdparty/ade/ade-0.1.1f/sources/ade/include/ade/typed_graph.hpp:106:53: error: ‘m_srcGraph’ was not declared in this scope 106 | return *reinterpret_cast<const ade::Graph*>(m_srcGraph); | ^~~~~~~~~~ /home/xkf/opencv-4.5.5/build/3rdparty/ade/ade-0.1.1f/sources/ade/include/ade/typed_graph.hpp: In constructor ‘ade::ConstTypedGraph<Types>::ConstTypedGraph(const ade::Graph&): /home/xkf/opencv-4.5.5/build/3rdparty/ade/ade-0.1.1f/sources/ade/include/ade/typed_graph.hpp:122:9: error: class ‘ade::ConstTypedGraph<Types>’ does not have any field named ‘m_srcGraph’ 122 | m_srcGraph(reinterpret_cast<std::uintptr_t>(&graph)) | ^~~~~~~~~~ /home/xkf/opencv-4.5.5/build/3rdparty/ade/ade-0.1.1f/sources/ade/include/ade/typed_graph.hpp:122:42: error: ‘uintptr_t’ in namespace ‘std’ does not name a type 122 | m_srcGraph(reinterpret_cast<std::uintptr_t>(&graph)) | ^~~~~~~~~ /home/xkf/opencv-4.5.5/build/3rdparty/ade/ade-0.1.1f/sources/ade/include/ade/typed_graph.hpp:122:37: note: ‘std::uintptr_t’ is defined in header ‘<cstdint>’; did you forget to ‘#include <cstdint>’? 122 | m_srcGraph(reinterpret_cast<std::uintptr_t>(&graph)) | ^~~ /home/xkf/opencv-4.5.5/build/3rdparty/ade/ade-0.1.1f/sources/ade/include/ade/typed_graph.hpp: In constructor ‘ade::ConstTypedGraph<Types>::ConstTypedGraph(const ade::ConstTypedGraph<OtherTypes ...>&): /home/xkf/opencv-4.5.5/build/3rdparty/ade/ade-0.1.1f/sources/ade/include/ade/typed_graph.hpp:130:9: error: class ‘ade::ConstTypedGraph<Types>’ does not have any field named ‘m_srcGraph’ 130 | m_srcGraph(other.m_srcGraph) | ^~~~~~~~~~ /home/xkf/opencv-4.5.5/build/3rdparty/ade/ade-0.1.1f/sources/ade/include/ade/typed_graph.hpp: In instantiation of ‘ade::Graph& ade::TypedGraph<Types>::getGraph() const [with Types = {ade::passes::TopologicalSortData}]’: /home/xkf/opencv-4.5.5/build/3rdparty/ade/ade-0.1.1f/sources/ade/include/ade/typed_graph.hpp:238:16: required from ‘ade::Graph::NodesListRange ade::TypedGraph<Types>::nodes() [with Types = {ade::passes::TopologicalSortData}; ade::Graph::NodesListRange = ade::util::Range::MapRange<ade::util::Range::IterRange<__gnu_cxx::__normal_iterator<std::shared_ptr<ade::Node>*, std::vector<std::shared_ptr<ade::Node> > > >, ade::Graph::HandleMapper>]’ /home/xkf/opencv-4.5.5/build/3rdparty/ade/ade-0.1.1f/sources/ade/source/topological_sort.cpp:39:40: required from here /home/xkf/opencv-4.5.5/build/3rdparty/ade/ade-0.1.1f/sources/ade/include/ade/typed_graph.hpp:167:53: error: ‘const class ade::TypedGraph<ade::passes::TopologicalSortData>’ has no member named ‘m_srcGraph’ 167 | return *reinterpret_cast<ade::Graph*>(this->m_srcGraph); | ~~~~~~^~~~~~~~~~
最新发布
08-13
cc1plus: warning: ‘-Wabi’ won’t warn about anything [-Wabi] cc1plus: note: ‘-Wabi’ warns about differences from the most up-to-date ABI, which is also used by default cc1plus: note: use e.g. ‘-Wabi=11’ to warn about changes from GCC 7 In file included from /usr/include/boost/detail/endian.hpp:9, from /home/csh/pcl-1.8.1/common/include/pcl/PCLPointCloud2.h:11, from /home/csh/pcl-1.8.1/common/include/pcl/pcl_base.h:55, from /home/csh/pcl-1.8.1/segmentation/include/pcl/segmentation/organized_multi_plane_segmentation.h:44, from /home/csh/pcl-1.8.1/segmentation/src/organized_multi_plane_segmentation.cpp:42: /usr/include/boost/predef/detail/endian_compat.h:11:161: note: #pragma message: The use of BOOST_*_ENDIAN and BOOST_BYTE_ORDER is deprecated. Please include <boost/predef/other/endian.h> and use BOOST_ENDIAN_*_BYTE instead 11 | t/predef/other/endian.h> and use BOOST_ENDIAN_*_BYTE instead") | ^ In file included from /home/csh/pcl-1.8.1/segmentation/include/pcl/segmentation/organized_multi_plane_segmentation.h:48, from /home/csh/pcl-1.8.1/segmentation/src/organized_multi_plane_segmentation.cpp:42: /home/csh/pcl-1.8.1/segmentation/include/pcl/segmentation/plane_coefficient_comparator.h: In member function ‘const std::vector<float>& pcl::PlaneCoefficientComparator<PointT, PointNT>::getPlaneCoeffD() const’: /home/csh/pcl-1.8.1/segmentation/include/pcl/segmentation/plane_coefficient_comparator.h:145:64: error: non-member function ‘const boost::shared_ptr<std::vector<float> >& pcl::getPlaneCoeffD()’ cannot have cv-qualifier 145 | const boost::shared_ptr<std::vector<float>>& getPlaneCoeffD() const ; | ^~~~~ /home/csh/pcl-1.8.1/segmentation/include/pcl/segmentation/plane_coefficient_comparator.h:147:13: error: invalid initialization of reference of type ‘const std::vector<float>&’ from expression of type ‘const boost::shared_ptr<std::vector<float> >’ 147 | return plane_coeff_d_; | ^~~~~~~~~~~~~~ make[2]: *** [segmentation/CMakeFiles/pcl_segmentation.dir/build.make:167:segmentation/CMakeFiles/pcl_segmentation.dir/src/organized_multi_plane_segmentation.cpp.o] 错误 1 make[1]: *** [CMakeFiles/Makefile2:1905:segmentation/CMakeFiles/pcl_segmentation.dir/all] 错误 2 make: *** [Makefile:163:all] 错误 2
03-21
--- stderr: card_drawing2 In file included from /usr/include/c++/11/pstl/glue_algorithm_defs.h:13, from /usr/include/c++/11/algorithm:74, from /opt/ros/humble/include/rclcpp/rclcpp/executor.hpp:18, from /opt/ros/humble/include/rclcpp/rclcpp/executors/multi_threaded_executor.hpp:25, from /opt/ros/humble/include/rclcpp/rclcpp/executors.hpp:21, from /opt/ros/humble/include/rclcpp/rclcpp/rclcpp.hpp:155, from /home/f972/assi_ws/src/card_drawing2/src/card_server.cpp:1: /usr/include/c++/11/functional: In instantiation ofstruct std::_Bind_check_arity<void (CardServer::*)(std::shared_ptr<card_interface::srv::String_Response_<std::allocator<void> > >), CardServer*, const std::_Placeholder<1>&, const std::_Placeholder<2>&>’: /usr/include/c++/11/functional:768:12: required from ‘struct std::_Bind_helper<false, void (CardServer::*)(std::shared_ptr<card_interface::srv::String_Response_<std::allocator<void> > >), CardServer*, const std::_Placeholder<1>&, const std::_Placeholder<2>&>’ /usr/include/c++/11/functional:789:5: required by substitution of ‘template<class _Func, class ... _BoundArgs> typename std::_Bind_helper<std::__is_socketlike<_Func>::value, _Func, _BoundArgs ...>::type std::bind(_Func&&, _BoundArgs&& ...) [with _Func = void (CardServer::*)(std::shared_ptr<card_interface::srv::String_Response_<std::allocator<void> > >); _BoundArgs = {CardServer*, const std::_Placeholder<1>&, const std::_Placeholder<2>&}]’ /home/f972/assi_ws/src/card_drawing2/src/card_server.cpp:13:38: required from here /usr/include/c++/11/functional:756:21: error: static assertion failed: Wrong number of arguments for pointer-to-member 755 | static_assert(_Varargs::value | ~~~~~ 756 | ? sizeof...(_BoundArgs) >= _Arity::value + 1 | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
03-31
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值