草庐IT

set_creation_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++ - 如何将 boost::graph 算法与 listS、setS 作为顶点/边缘容器一起使用?

使用boost::graph库的boost示例通常使用像这样的图usingnamespaceboost;typedefadjacency_list,property>graph;因此它们工作得很好。但我有一个图表typedefadjacency_listgraph;并且算法不是开箱即用的。在大多数情况下,必须提供用于查找特定顶点索引(整数值)的vertex_descriptor的映射。我想检查我的图是否是平面图并计算它的平面嵌入。我提供了一个顶点索引图,它确实以这种方式工作,例如connected_components算法,但显然不适用于boyer_myrvold_planarity_

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::set_intersection 在两个完全不同的容器上

我有一个简单的要求,我需要从另一个vector中的字符串主列表中找到一个vector中字符串的出现。一开始我可以很容易地做到这一点:vectorcustom_list;setmaster_list;vectortarget_list;std::sort(custom_list.begin(),custom_list.end());std::set_intersection(custom_list.begin(),custom_list.end(),master_list.begin(),master_list.end(),back_inserter(target_list));这工作得

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++ - boost::asio signal_set 处理程序仅在捕获到第一个信号后执行,并忽略相同类型的连续信号

我有一个程序,我想通过发送SIGINT将一些数据写入文件而不是立即退出来停止它。但是,如果程序的用户再次发送SIGINT,则程序应立即退出并忘记将数据写入文件。出于可移植性的原因,我想为此目的使用boost::asio。我最初的(简化的)方法(见下文)没有奏效。这是不可能的还是我遗漏了什么?处理程序似乎只被调用一次(打印出消息)并且程序总是在循环达到最大迭代次数时停止。voidhandler(constboost::system::error_code&error,intsignal_number){if(!error){staticboolfirst=true;if(first){s

c++ - set<string> 像数字一样排序

我尝试将字符串集作为数字进行排序。每个字符串长度可以达到50,它们实际上并不只是由数字组成。据我了解并在论坛中搜索,c++默认按字典顺序对字符串进行排序。有没有办法更改此默认行为以满足我的需要?我需要的是如下所示:setsolution;solution.insert("12X451");solution.insert("X23454");solution.insert("12345");solution.insert("12315");solution.insert("123111");solution.insert("5231");for(autos:solution){cout这

c++ - 在 C++ 中定义虚拟 get 和 set 函数被认为是一种好的做法吗?

如果我有一个简单的2级类层次结构,例如这个://level1classSpare_Part{private:stringname;doubleprice;public:Spare_Part();stringgetName(){returnname;}doublegetPrice(){returnprice;}virtualintgetQuantity(){return-1;};//mayalsodefineitaspurevirtual};//level2classOn_hand:publicSpare_Part{private:intquantity;stringlocation;p

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(