草庐IT

make_function

全部标签

c++ - g++ 链接问题 : In function `_start' : (. text+0x20): undefined reference to `main'

我收到对主要错误的undefinedreference-即使我已经定义了主要,并且(AFAICT),我已经正确链接了它。这是我的代码和我使用的命令://################################################//proj1.h#ifndef__SCRATCH_PROJ1_H#define__SCRATCH_PROJ1_HintaddOne(inti);#endif/*__SCRATCH_PROJ1_H*///################################################//proj1.cpp#include"pr

c++ - Qt Creator 在步骤 'make' 编译错误

我刚开始使用QtCreator创建C++GUI程序。我刚刚下载并安装了它,但编译过程抛出了错误。当我尝试编译我的项目时(非常简单,屏幕上只有一个QLabel...这是我的第一个项目)出现错误:qtcreator_ctrlc_stub:Commandlinefailed:C:\Users\andrew\Dropbox\Programming\C++\build-FirstGUIApp-Desktop_Qt_5_1_1_MSVC2012_32bit-Debug\Makefile10:04:35:Theprocess"C:\Users\andrew\Dropbox\Programming\C

c++ - 使用 -g 选项编译但 "Single stepping until exit from function main, which has no line number information"

我在使用gdb时遇到了一些问题。这是我在一个名为main.cpp的文件中的代码#includevoidmyfunc();intmain(){charmsg[]="HelloWorld!";myfunc();std::cout我使用这个命令来编译这段代码:g++-g-Wallmain.cpp-ofoo接下来,我使用了gdb:$gdbfoo(gdb)startTemporarybreakpoint1at0x80487c3Startingprogram:/home/laptop/workspace/fooTemporarybreakpoint1,0x080487c3inmain()(gdb)

c++ - std::function 在调用内部可变 lambda 时是否锁定互斥量?

除非另有说明,否则C++标准库对其类型提供以下保证:(1)读取操作(即处理const对象)是线程安全的。这意味着只要没有线程同时写入(应用非const操作)对象,多个线程就可以同时从对象读取而不会出现竞争条件。(2)多个线程可以同时读写任意对象,只要每个对象一次最多只能被一个线程访问。标准库需要用户类型的相同保证。(您可以在GotW#95中阅读这些内容或观看HerbatC++andBeyond2012对此的解释。)现在我的问题是,如果下面的结论是正确的:因为std::function的operator()是一个const成员函数,它需要是线程安全的。如果在构造时传入的仿函数有一个con

c++ - 哪些库对 std::make_shared 使用了 "We Know Where You Live"优化?

两年前,StephanT.Lavavejdescribedaspace-savingoptimization他在Microsoft的std::make_shared实现中实现了这一点,我从与他的交谈中了解到,Microsoft并不反对采用此优化的其他库实现。如果您确定其他库(例如,用于GnuC++、Clang、IntelC++以及Boost(用于boost::make_shared))是否采用了此实现,请提供答案。我还没有准备好访问那么多make_shared实现,我也不想深入研究那些我必须看看他们是否已经实现了WKWYL优化的东西,但我希望SO读者知道一些图书馆的答案。通过查看代码,

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++ - 在 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