草庐IT

shared_int

全部标签

c++ - 'make_shared' 不明确

除非定义了B0RKEN(就像命令行上的-DB0RKEN一样),否则编译以下内容:#include#include#includeusingboost::shared_ptr;usingboost::make_shared;usingmy_fn=std::function;voidfoo(){my_fnfn=[](){};#ifdefB0RKENshared_ptrk=make_shared(fn);#elseshared_ptrk=make_shared(0);#endif}boost似乎在玩一些有趣的游戏,这可能是这段代码出现这个问题的原因。我不明白的是为什么它适用于shared_p

c++ - 使用和何时使用 int16_t、int32_t、int64_t 和分别为 short int、int、long int、long

使用和何时使用int16_t、int32_t、int64_t以及分别使用short、int,长。C++中有太多该死的类型。对于整数,什么时候使用一个而不是另一个是正确的? 最佳答案 当精度很重要时,使用明确定义的类型。当它不是时,使用不太确定的。使用更精确的永远不会错。当您使用灵活的时,有时会导致错误。 关于c++-使用和何时使用int16_t、int32_t、int64_t和分别为shortint、int、longint、long,我们在StackOverflow上找到一个类似的问题:

c++ - 用 boost::shared_ptr<std::list<T>> 初始化 boost::shared_ptr<std::vector<T>>

我想初始化一个boost::shared_ptr>vec在构造函数中使用boost::shared_ptr>list初始化列表?这可能吗?我试过这个:测试.hppclassTest{public:Test(boost::shared_ptr>list);private:boost::shared_ptr>vec;};测试.cppTest::Test(boost::shared_ptr>list):vec(list->begin(),list->end()){}部分错误信息:Test.cpp:Inconstructor‘Test::Test(boost::shared_ptr>>)’:T

c++ - 从 abs(double) 而不是 int 获得双重结果

我需要计算两个double值之差的绝对值,并得到一个double结果。相反,我得到一个int。#include//...printf("a:%sb:%sdelta:%sabs:%s\n",typeid(a).name(),typeid(b).name(),typeid(a-b).name(),typeid(abs(a-b)).name());//Prints:a:db:ddelta:dabs:i如果减法的结果已经是double,为什么abs不使用doubleabs(doublex);签名?事实上,它怎么可能返回一个整数呢?最重要的是,我如何强制它返回一个double?以防万一,a和b实

c++ - uint64_t 中的唯一值在 int64_t 中是否也是唯一的

给定一个唯一的(std::uint64_t类型)整数vector,如果我将(std::uint64_t类型)的vector转换为(std::int64_ttype)integers,能保证唯一吗?像这样类型转换std::vectorunsignedVec;std::vectorsignedVec(unsignedVec.begin(),unsignedVec.end()); 最佳答案 willitbeguaranteedtobeunique?形式上它是实现定义的,但在任何合理的平台上它应该是唯一的。(特别是考虑到int64_thas

c++ - 类型到 int 的映射

我有两个c++程序需要有一个映射type->int,它在编译时已知并且两个程序之间相等。此外,我想在编译时自动确保map是一对一的。你会如何解决这个问题?(允许使用c++0x扩展)。第一部分很简单:分享一个templatestructmap;templatestructmap{enum{val=...;};};程序之间。(第二部分意味着我不想在我的程序中的某处意外地为两种不同的类型定义相同的val。) 最佳答案 确保uniqeid的一种方法是滥用友元函数定义templatestructmarker_id{staticintconst

c++ - 包括 tr1::shared_ptr

我已经包括了#include在我的类(class)文件中,当我尝试编译我的类时,出现以下错误:>Infileincludedfromaccount.h:16:0:/usr/include/c++/4.4.3/tr1/shared_ptr.h:61:46:error:'_Lock_policy'hasnotbeendeclared/usr/include/c++/4.4.3/tr1/shared_ptr.h:63:30:error:expectedtemplate-namebefore'::__shared_count()':有谁知道究竟是什么导致了这个错误?

c++ - `shared_ptr` 破坏了对象的常量性

考虑以下代码:classB{intx;public:B():x(10){}intget_x()const{returnx;}voidset_x(intvalue){x=value;}};classA{boost::shared_ptrb_;public:boost::shared_ptrget_b()const{returnb_;}//(1)};voidf(constA&a){boost::shared_ptrb=a.get_b();intx=b->get_x();b->set_x(++x);//(2)}intmain(){Aa;f(a);return0;}在这段代码(2)中,get_

C++ 标准 : default "const T& value" in vector constructor for type 'int'

explicitvector(size_typen,constT&value=T(),constAllocator&=Allocator());vectorvec(10);cout::const_iteratoriter=vec.begin();iter!=vec.end();++iter){coutVS2010的输出:vec.size:100000000000问题>:根据最新的C++标准,当我们使用vectorObject(size_type)定义一个vector对象时,默认的int值是多少?在这里你可以看到,VS2010输出0作为默认的int值。但我不知道这是否是C++标准所要求的

c++ - boost shared_ptr 运算符 =

这里是代码示例classA{inti;public:A(inti):i(i){}voidf(){prn(i);}};intmain(){A*pi=newA(9);A*pi2=newA(87);boost::shared_ptrspi(pi);boost::shared_ptrspi2(pi2);spi=spi2;spi->f();spi2->f();pi->f();pi2->f();}输出:8787087问题是为什么输出中是0?文档注释:效果:等同于shared_ptr(r).swap(*this)。但是如果shared_ptr对象刚刚交换,结果应该是9。如果第一个对象被删除,应该有S