草庐IT

function_char-length

全部标签

c++ - 错误 C2448 : function-style initializer appears to be a function definition

我有以下一段代码-voidCommandProcessor::ReplacePortTag((void*)portID){std::stringtemp=std::string.empty();intstart=0;for(inti=0;i"){temp+=CommandProcessor::fileContents.substr(start,i-start);temp+=portID;start=i+6;}}temp+=CommandProcessor::fileContents.substr(start+6,CommandProcessor::fileContents.length

c++ - 当输入 char 代替 int 时避免无限循环

我正在做一个银行系统项目,需要确保每个输入都是有效的(程序必须是健壮的)。如果输入无效,则用户必须重新输入。但是当我有一个int类型的变量并且用户输入char类型时,一个无限循环开始了。例如:inti;cin>>i;如果用户输入char无限循环开始。我怎样才能避免它并再次要求用户输入?谢谢 最佳答案 无限循环的原因:cin进入失败状态,这使得它忽略对它的进一步调用,直到错误标志和缓冲区被重置。cin.clear();cin.ignore(100,'\n');//100-->askscintodiscard100charactersf

C++ 异常返回类型为什么是 char*

有人可以解释为什么自写的C++异常,从异常继承返回一个char*而不是一个字符串?classmyexception:publicexception{virtualconstchar*what()constthrow(){return"Myexceptionhappened";}}myex;来源:http://www.cplusplus.com/doc/tutorial/exceptions/ 最佳答案 由于std::exception被设计为所有异常的基类,因此接口(interface)的编写方式使得特化不需要可能抛出的代码。他们可

c++ - 在 Visual Studio 中调用 std::swap 时的 std::bad_function_call

我正在尝试将我的代码从Linux移植到Windows。但是,对于VisualStudio,我的代码因以下错误而崩溃:MicrosoftC++exception:std::bad_function_callatmemorylocation这是我的代码:#includeclassFoo{public:Foo(int):m_deleter{[](){}}{}Foo(constFoo&)=delete;Foo(Foo&&)=default;Foo&operator=(constFoo&)=delete;Foo&operator=(Foo&&)=default;~Foo(){m_deleter(

c++ - 在成员初始化列表中使用 std::function

我有一个类型定义:typedefS32(iMyDataClass1::*getDataFunction_t)(void);和类型:structfunctionMap_t{std::vectorpDataFunctionTable;structdataRequestor_tdataRequestor;};然后我有一个成员变量:functionMap_tFnMap1;然后我在成员初始值设定项列表中设置:myClass::myClass():FnMap1({{&iMyDataClass1::getData1,&iMyDataClass1::getData2,&iMyDataClass1::g

c++ - 从 VS 2012 中的 lambda 返回值构造 std::function 时崩溃

此C++代码使用VS2012成功编译但在运行时崩溃:#include#includevoidf(){std::coutfilter(get_f());//crashhere!!!return0;}如果我们将get_f更改为:autoget_f=[](){returnf;};然后程序运行没有崩溃。是这段代码的问题还是编译器/标准库的bug?我没有使用较新版本的VisualStudio进行测试。 最佳答案 在我看来,这像是标准库(或可能是编译器)的问题。使用VS2013,它可以毫无问题地编译和运行。如果我们添加代码来调用同样运行的fil

python - Boost.Python 和 Boost.Function

我想包装一个boost::function类成员,以便可以按以下方式使用它:usingnamespaceboost;usingnamespaceboost::python;structgui_button_t{functionon_pressed;};class_("GuiButton",init()).def("on_pressed",&gui_button_t::on_pressed);然后在Python中:defcallback_function():print'buttonhasbeenpressed'button=GuiButton()button.on_pressed=ca

c++ - 仿函数/函数对象的 is_function 类型特征

考虑以下代码:structBar{voidoperator()(){}};intmain(){std::cout::value输出为false。这里并不奇怪,因为仿函数Bar不符合函数类型§8.3.5Functions[dcl.fct]。现在考虑以下代码:structBar{voidoperator()(){}};intmain(){std::cout::value请注意Bar之后的括号。输出为true。Bar()是如何限定为函数类型的?我的猜测是这是一个最令人烦恼的解析案例,但它在模板参数列表中怎么可能呢? 最佳答案 嗯,我不认为

c# - 如何将带有 unsigned char* 的结构从 C# 传递到 C++?

我有一些带有结构描述和一些方法的C++dll:structMSG_STRUCT{unsignedlongdataSize;unsignedchar*data;}和功能例如:unsignedlongReadMsg(unsignedlongmsgId,MSG_STRUCT*readMsg){readMsg->dataSize=someDataSize;readMsg->data=someData;}所以我想从C#调用这个函数:[StructLayout(LayoutKind.Sequential)]structMSG_STRUCT{UInt32dataSize;byte[]data;}[D

c++ - 错误 : 'Failed to specialize function template' C2893 'std::invoke'

我正在VisualStudio2013中编写MFC程序,但我不断收到以下两个错误错误C2893无法特化函数模板'unknown-typestd::invoke(_Callable&&,_Types&&...)'和错误C2672“std::invoke”:找不到匹配的重载函数错误与文件xthread第238行有关我是c++/MFC的新手,我正在尝试编写一个将在后台运行到系统时间的函数。这是我使用的代码:voidtask1(ExperimentTab&dlg){while(true){CStringshowtime=CTime::GetCurrentTime().Format("%H:%M