草庐IT

Union_map

全部标签

c++ - 使用以位集为键的 map 时出现问题

我正在尝试使用bitset作为键在C++中创建一个map。但是编译器会生成以下错误消息Infileincludedfrom/usr/include/c++/4.6/string:50:0,from/usr/include/c++/4.6/bits/locale_classes.h:42,from/usr/include/c++/4.6/bits/ios_base.h:43,from/usr/include/c++/4.6/ios:43,from/usr/include/c++/4.6/ostream:40,from/usr/include/c++/4.6/iostream:40,fro

c++ - Union 在 OOP 中的使用

union可以像类和结构一样用作类型(有一些限制)。它可以有成员函数。它可以用作OOP结构。据我所知,union只是导入到C++中以保持与C的向后兼容性。在这些年的编程中,我从未像使用类或结构那样使用union体作为OOP构造。Union作为OOP构造(而不仅仅是作为数据类型)是否有任何实际用途,或者它只是语言中永远没有用的残留部分?编辑:该标准明确允许union充当OOP构造。它允许union中的成员函数。以下代码编译和工作并且符合标准:unionA{inta;intk;voiddoSomething(){}};intmain(){Aobj;inti=obj.a;obj.doSome

c++ - 是否有 auto_ptr 的替代品可以与 c++11 中的 boost ptr_map 一起使用

在c++11中,auto_ptr已弃用,取而代之的是更合理的unique_ptr。唉,如果你使用boost::ptr_map,auto_ptr就完成了一个非常方便的用途:std::auto_ptrpLayer(newLayer());mRawLayerPtrMap.insert(layerName,pLayer);是否有可能使用与c++11类似的东西。这个我知道Layer*pLayer=newLayer();mFusedLayers.insert(fusedLayerName,pLayer);有效,但auto_ptr在一些更复杂的场景中有它的优点。是否有适用于C++11的替代品?

c++ - std::size 和 std::map 的最大大小?

std::size和std::map的最大大小是多少?有没有办法增加这个数字?谢谢! 最佳答案 您可以通过调用Container::max_size()获得每个标准库容器的最大大小在上面。如果在编译时需要理论最大大小值,请使用std::numeric_limits::max(). 关于c++-std::size和std::map的最大大小?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questi

c++ - std::map::clear 和元素的析构函数

析构函数是否在std::map上被调用?std::map::clear时的元素用来?我尝试调试std::map但看不到std::string析构函数被调用。任何人都可以帮助我理解吗?文档说明它被调用了,但我没有注意到它。 最佳答案 文档是正确的,它确实被调用了。销毁将通过方法std::allocator::deallocate()完成。.在调试器中跟踪它。http://www.cplusplus.com/reference/std/memory/allocator/ 关于c++-std:

c++ - 插入 unordered_map 时没有匹配函数

我声明一个unordered_map如下:boost::unordered_map,t_torrent>torrent_ins;然后向其中插入一个元素(如果键不存在,该映射将返回新元素的引用)t_torrent&torrent_in=torrent_ins[to_array(in)];但是我收到一条错误信息:../src/Tracker/torrent_serialization.cpp:30:instantiatedfromhere/usr/local/include/boost/functional/hash/extensions.hpp:176:error:nomatchingf

c++ - 为什么在使用 std::map::insert() 时编译顺序有时会导致段错误?

我有一个类叫做Controller,在其中,我有一个名为Button的类.Controller包含几个Button不同类型的实例(例如button_type_a、button_type_b)。controller.h#ifndef__controller__#define__controller__classController{public:classButton{public:Button(inttype=-1);private:inttype;};Controller();ButtonA;ButtonB;ButtonX;ButtonY;};#endif按钮类型为ints,我希望能

c++ - STL 允许使用指向不同 map 的迭代器删除 map 的键/值吗?

所以,我偶然发现的是:std::mapmap1;std::mapmap2;map1[2.5]=11;map1[3.5]=12;map2[2.5]=21;map2[3.5]=22;std::map::iteratoriterMap1=map1.find(2.5);//Iwillnowtrytoeraseakey/valuepairinmap2withaniterator//thatpointstomap1.Thisisbad/wrong.ButIamsurprised//thisisallowed.map2.erase(iterMap1);//whatdoyouthinkwouldbep

c++ - 英特尔 Embree 中的这个 union 有什么作用?

这是来自Intel的Embreecode中的vec3fa.h.struct__aligned(16)Vec3fa{typedeffloatScalar;enum{N=3};union{__m128m128;struct{floatx,y,z;union{inta;floatw;};};};//otherstuffinstruct};外union在做什么?内心的结合对我来说更加神秘。代码中从未引用a和w变量。看起来这提供了一种使用适当的别名读取和写入m128、x、y和z的方便且干净的方法。它是如何工作的?int是怎么参与进来的?? 最佳答案

c++ - union 正确用法

我对union体的理解是它的所有值都分配在同一个内存地址,并且内存空间与union体的最大成员一样大。但我不明白我们将如何实际使用它们。根据TheC++ProgrammingLanguage,这是一个最好使用union的代码.enumType{str,num};structEntry{char*name;Typet;char*s;//usesift==strinti;//useiift==num};voidf(Entry*p){if(p->t==str)couts;//...}在此之后Bjarne说:Thememberssandicanneverbeusedatthesametime,