草庐IT

Union-Find

全部标签

c++ - union 中未命名结构的同名成员是错误还是 GCC 错误?

下面的代码可以在VisualC++中编译成功.我喜欢它,它很甜!#include#ifdef_MSC_VER#pragmawarning(push)#pragmawarning(disable:4201)#pragmapack(push,1)#definePACKED#else#definePACKED__attribute__((__packed__))#endifunionA{struct{inta:1;intb:2;intc1:29;}PACKED;struct{inta:1;intb:2;intc2:28;intd:1;}PACKED;intval;}PACKED;#ifdef

Mongodb find 查询与 $near 和坐标不起作用

我正在尝试使用mongodb中的一些地理定位功能。使用带有$near的查找查询似乎不起作用!我的数据库中目前有这个对象:{"Username":"Deano","_id":{"$oid":"533f0b722ad3a8d39b6213c3"},"location":{"type":"Point","coordinates":[51.50998,-0.1337]}}我也设置了以下索引:{"v":1,"key":{"location":"2dsphere"},"ns":"heroku_app23672911.catchmerequests","name":"location_2dspher

Mongodb find 查询与 $near 和坐标不起作用

我正在尝试使用mongodb中的一些地理定位功能。使用带有$near的查找查询似乎不起作用!我的数据库中目前有这个对象:{"Username":"Deano","_id":{"$oid":"533f0b722ad3a8d39b6213c3"},"location":{"type":"Point","coordinates":[51.50998,-0.1337]}}我也设置了以下索引:{"v":1,"key":{"location":"2dsphere"},"ns":"heroku_app23672911.catchmerequests","name":"location_2dspher

c++ - std::vector 的 std::lower_bound 比 std::map::find 慢

我编写了一个类来充当顺序容器(std::vector/std::queue/std::list)的包装器,以具有std::map的接口(interface),用于使用少量小对象时的性能。考虑到已经存在的算法,编码非常简单。这段代码显然是高度从我的完整代码中删减的,但显示了问题。template,classundertype_=std::vector>>classassociative{public:typedeftraits_key_compare;typedefkey_key_type;typedefmapped_mapped_type;typedefstd::pairvalue_t

c++ - 访问 union 中相同类型的非事件成员

我有这样的事情:unionDataXYZ{structcomplex_t{floatreal,imag;}complex;structvector_t{floatmagnitude,phase;}vector;};我有一些这些vector,作为通用工作空间内存,我在语义上下文之后相应地使用这些字段。我知道当最后一个事件成员是另一个字段(和类型?)时,读取union中的字段是未定义的行为。当类型和布局完全匹配时,这是否重要?我一直在评论一些其他类似的问题,要求提供保证行为的引用资料,但什么都没有出现-因此提出了这个问题。 最佳答案 是

c++ - union 内的 'protected' 关键字有什么用?

这个问题在这里已经有了答案:Whatisthepointof'protected'inaunioninC++(1个回答)关闭7年前。我检查了protected访问说明符可以在class、struct以及union中使用。我知道protected访问说明符意味着成员将是私有(private)的,但对派生类可见。我无法想到一个合理的用例,其中union内的protected关键字会很有用,因为union不能成为继承层次结构的一部分。既然在union中private和protected没有区别,为什么还要在union中允许protected呢? 最佳答案

c++ - C/C++ union 中元素的内存位置

我在C中有一个这样的union:unionAUnion{structCharBuf{char*buf;size_tlen;}charbuf;uint8_tnum;doublefp_num;};我的问题是,如果给出以下条件,我能否保证:unionAUnionu;那么以下是正确的:&u==&u.num&u==&u.fp_num&u==&u.charbuf即它们都从存储u的内存段的开头开始。对于使用gccversion5.3.0和-std=c11编译的这个C程序,上述情况是正确的:#include#include#includeunionAUnion{structCharBuf{char*b

c++ -/usr/bin/ld : cannot find -lboost_system-mt

我最近从boost1.40升级到了1.45,完全删除了以前的boost目录,下载了1.45的源代码并重建了我想要的库。然后我使用bjaminstall安装了这些库。我的机器上没有其他任何变化,但是,现在当我构建我的C++程序时,我收到以下链接错误:/usr/bin/ld:cannotfind-lboost_system-mt我搜索了,该文件确实不存在。似乎mt库不再是库的一部分-还是我遗漏了什么?我该如何解决这个问题? 最佳答案 好吧,我在ubuntu12.04(x86_64)上通过良好的scattergun方法解决了这个错误mak

c++ - 运行C++程序时出现"The system cannot find the file specified"

我安装了VisualStudio2010。我编写了一个简单的代码,我确信它是正确的,但不幸的是,当我运行该代码时,我收到以下错误。这是我的代码:#includeusingnamespacestd;intmain(){cout这是错误:Unabletostartprogram'C:\Users\Soheil\Desktop\Newfolder\sam\Debug\sam.exeThesystemcannotfindthefilespecified你能帮我解决这个问题吗?我应该在具体目录?我花了很多时间来解决这个问题还没有成功。 最佳答案

c++ - 用原语 union 公共(public)初始序列

我试图更好地理解一个关于union和通用初始序列规则的相当令人惊讶的发现。常见的初始序列规则说(class.mem23): Inastandard-layoutunionwithanactivememberofstructtypeT1,itispermittedtoreadanon-staticdatamembermofanotherunionmemberofstructtypeT2providedmispartofthecommoninitialsequenceofT1andT2;thebehaviorisasifthecorrespondingmemberofT1werenomin