草庐IT

is_const

全部标签

C++ Linux : error: ‘move’ is not a member of ‘std’ how to get around it?

所以在我的VS2010上我可以编译如下代码:boost::shared_ptrinternal_thread;boost::packaged_taskinternal_task_w(boost::bind(&thread_pool::internal_run,this,internal_thread));internal_thread=boost::shared_ptr(newboost::thread(std::move(internal_task_w)));前两行在boost1.47.0和linux上没问题...但是在std::move上它给出了error:‘move’isnota

C++ const 语义引用

如果代码中有如下内容:func(constbase&obj)const语义是什么意思?这里的常数是什么?obj是对非常量对象的const引用还是对const对象的非常量引用? 最佳答案 没有“非常量”引用这样的东西,也就是说,引用总是绑定(bind)到同一个对象,而且没有办法改变它。"consttype&"表示对const类型的引用。 关于C++const语义引用,我们在StackOverflow上找到一个类似的问题: https://stackoverflo

c++ - 警告 : value computed is not used

为什么我在“BIO_flush(b64);”行收到警告消息“警告:未使用计算值”我怎样才能摆脱它?unsignedchar*my_base64(unsignedchar*input,intlength){BIO*bmem,*b64;BUF_MEM*bptr;b64=BIO_new(BIO_f_base64());bmem=BIO_new(BIO_s_mem());b64=BIO_push(b64,bmem);BIO_write(b64,input,length);BIO_flush(b64);BIO_get_mem_ptr(b64,&bptr);unsignedchar*buff=(u

c++ - 尝试使用 std::add_const 将 T& 转换为 const T&

我有一个T&,它有一个函数的const和非常量版本。我想调用该函数的const版本。我尝试使用std::add_const将T&转换为constT&但它不起作用。我做错了什么,我该如何解决?这是一个简单的例子。voidf(int&){std::cout::type>(r));}输出:int& 最佳答案 类型特征是解决这个问题的一种非常费力的方法。只需使用模板类型推导:voidf(int&){std::coutconstT&make_const(T&t){returnt;}intmain(){inta=0;int&r=a;f(make

C++11 统一初始化 : Field initializer is not constant

我正在尝试像这样实例化一组字符串:classPOI{public:...staticconststd::setTYPES{"restaurant","education","financial","health","culture","other"};...}现在,当我这样做时,我得到了这些错误(全部在这一行):error:fieldinitializerisnotconstantstaticconststd::setTYPES{"restaurant","education","financial","health","culture","other"};error:in-class

c++ - 使 std::unique<T> 与 std::unique<const T, CustomDeleterType> 兼容

在代码中,我为特定对象定义了3个std::unique_ptr指针类型:typedefstd::unique_ptrnonConstPtrDefaultDelete;typedefstd::unique_ptr>nonConstPtrCustomDelete;typedefstd::unique_ptr>ConstPtrCustomDelete;我遇到了一个用例,我需要将nonConstPtrDefaultDelete转换为ConstPtrCustomDelete并将nonConstPtrCustomDelete转换为ConstPtrCustomDelete。换句话说:nonConst

c++ - 模板中的 "const const T"

以下代码可在G++4.4.0和MSVC2008Express上编译和运行。#includetemplatestructA{protected:Tv;public:constTget()const{returnv;}A(Tv_):v(v_){}};classB:publicA{public:voiddoSomething()const{constint*tmp=get();std::cout(p){}};intmain(intargc,char**argv){inta=134;Bb(&a);constB&c=b;b.doSomething();c.doSomething();return

c++ - 错误 : request for member '..' in 'this' , 是非类类型 '--* const'

这是我的第一个问题。请原谅,我刚刚进入C++并开始使用DS。堆叠!!!我的代码:我认为usingnamespacestd;typedefcharstackElement;classStack{public:stackElement*contents;//dynamicallyallocated:aswedonotknowwhatwouldbethesizeofourarray.inttop,maxSize;//currentTopindexinthearray//maxsizeofthearray;weneedittoknowifthearrayisfullStack(intmaxSi

c++ - 通过 const 引用传递 Qt 类

众所周知,Qt类使用copy-on-wite按值传递时。因此,直到需要时才进行复制。当只需要对对象进行只读访问时,我已经看到很多次通过const引用传递Qt类。为什么人们传递constQString&而不是简单的QString如果在这两种情况下都没有完成复制? 最佳答案 这是因为魔法是有代价的。QString不会复制整个字符串,但会计算引用。QString的多次复制会减慢程序的速度。如果constQString&足以满足您的需求,为什么不使用它呢?它仍然更快。 关于c++-通过const

C++ 错误 : deduced conflicting types for parameter 'T' string vs const char *

因此,我正在为双端队列容器编写一个简单的模板化搜索函数。这是代码:templatevoidsearchInDequeFor(std::dequeDeque,TsearchValue){for(constauto&element:Deque){if(Deque.empty()){std::cout下面是我在main中调用函数的方式:dequemyDeque={"apple","banana","pear","blueberry"};searchInDequeFor(myDeque,"pear");这是我遇到的错误:candidatetemplateignored:deducedconfl