草庐IT

const-ref

全部标签

为 Ruby FFI 接口(interface)从字符串转换为 const char* 时的 C++ 字符编码

我正在使用一个外部C++库,它执行一些HTTPS通信并提供XML服务器响应。在服务器端,响应是通过ISO-8859-15编码的,我得到一个std::string表示来自API的响应。当我打印出来/将其写入文件时,它看起来是正确的。必须将std::string和int错误代码传递给我的外部调用方。所以我在结构中返回这两个值:extern"C"{structFoobarResponse{constchar*responseText;intreturnCode;};}不幸的是,我必须借助std::c_str()将std::string响应转换为constchar*C风格的字符串表示形式之前。

c++ - 为什么 boost::any 禁止转发 const&&?

相关代码如下://PerfectforwardingofValueTypetemplateany(ValueType&&value,typenameboost::disable_if>::type*=0//disableifvaluehastype`any&`,typenameboost::disable_if>::type*=0)//disableifvaluehastype`constValueType&&`:content(newholder::type>(static_cast(value))){}据我所知,可以使用复制构造函数从const&&构造。我使用boost1.55.0

c++ - const 和 constexpr 最终会是一回事吗?

我刚看了答案constvsconstexpronvariables我正在看这个GoogleTechTalkaboutC++11/14features,其中据说,在函数方面,将来可能不需要constexpr,因为编译器会进化以自行解决。最后,我知道Java编译器和JVM努力找出类(或任何变量可能)在构造后是不可变的-无需您明确说明-并根据这一事实进行各种邪恶的优化。那么,问题来了:const和constexpr的命运最终会是同一件事吗?也就是说,即使编译器不能保证进行运行时初始化等,它最终是否会尽可能(基本上)这样做?当这种情况发生时,其中一个关键字不会是多余的吗?(就像内联正在成为,也

c++ - std::transform 中的 [] const_iterator::value_type 是什么意思

具体代码在这里。第15行在做什么(调用转换)?有人可以解释为什么输出01234吗?另一方面,如果我在第15行将cb更改为++cb,它会输出01110。第15行的返回值在做什么?#include#include#include#include#includeintmain(){typedefstd::listL;Ll(5);typedefL::const_iteratorCI;CIcb=l.begin(),ce=l.end();typedefL::iteratorI;Ib=l.begin();std::transform(cb,--ce,++b,[](CI::value_typen){r

c++ - 无法在 MFC/C++ 项目中将参数 1 从 'const wchar_t *' 转换为 'LPCTSTR'

我在线上遇到编译错误:MessageBox(e.getAllExceptionStr().c_str(),_T("Errorinitializingthesoundplayer"));Error4errorC2664:'CWnd::MessageBoxA':cannotconvertparameter1from'constwchar_t*'to'LPCTSTR'c:\users\daniel\documents\visualstudio2012\projects\mytest1\mytest1\main1.cpp1411MyTest1我不知道如何解决这个错误,我尝试了以下方法:Mess

c++ - 来自 const_iterator 取消引用的赋值会导致未定义的行为吗?

此代码是对我在其他地方真正尝试做的事情的简化测试。我有一个函数,它接受一个“ref-to-ptr”参数并将其修改为从指针列表中返回一个指针。#include#includeusingnamespacestd;typedefint*intp;typedefstd::listintplist;intplistmyList;voidfunc(intp&arg)//(1){intplist::const_iteratorit=myList.begin();std::advance(it,2);arg=*it;}intmain(){myList.push_back(newint(1));myLi

c++ - 使用 static、const、constexpr 的全局声明/初始化

在C++或C++11中,对于以下声明//初始化,//globalscopeconstinta=1;//line1staticconstintb=2;//line2constexprintc=3;//line3staticconstexprintd=4;//line4constexprinte=a+b+c*d;//line5staticconstexprintf=a-b-c*d;//line6Thisquestion表示在文件范围内,C++中的第1行和第2行没有区别。3号线和4号线呢?第4行和第5行有区别吗?第5行和第6行有区别吗? 最佳答案

c++ - __attribute((const)) 的不一致 gcc 行为

我在gcc中遇到了一个关于用__attribute((const))标记的运算符和函数的非常奇怪的行为。逻辑和算术运算符导致不同的优化,我不明白为什么。这并不是真正的错误,因为__attribute((const))只是一个提示,不能保证其效果,但这仍然非常令人惊讶。谁有任何解释?这是代码。所以我定义了一个__attribute((const))函数:intf(int&counter)__attribute((const));intf(int&counter){++counter;return0;}然后我定义了一个运算符(operator)测试宏。这是通过宏而不是模板/仿函数完成的,以

iOS FB SDK apprequests 的传入 URL 缺少 ref=notif、request_ids、app_request_type

我正在使用iOSFBSDK(在ParseF/W中烘焙)发送应用请求邀请,使用[facebookdialog:@"apprequests"andParams:paramsandDelegate:nil];]请求被正确发送并且也出现在被邀请者的帐户中。当我点击请求时,Facebook应用程序正确启动了我的应用程序。此时,我正在检查要处理的传入URL并获取request_ids等。FB(http://developers.facebook.com/docs/tutorials/ios-sdk-games/requests/)上的示例代码表示传入URL应采用以下格式fb480369938658

spring - 在 Spring 中何时使用 <ref bean> 以及何时使用 <ref local>?

何时使用以及何时使用Spring? 最佳答案 Specifyingthetargetbeanbyusingthebeanattributeofthereftagisthemostgeneralform,andwillallowcreatingareferencetoanybeaninthesameBeanFactory/ApplicationContext(whetherornotinthesameXMLfile),orparentBeanFactory/ApplicationContext.Thevalueofthebeanatt