草庐IT

-std=gnu99

全部标签

c++ - 错误 : no matching function for call to ‘std::vector<std::__cxx11::basic_string<char>>::push_back(int&)’

我是C++的新手。当我运行我的代码时出现此错误:(BigSorting.cpp:Infunction‘intmain(int,constchar**)’:BigSorting.cpp:13:22:error:nomatchingfunctionforcallto‘std::vector>::push_back(int&)’v.push_back(m);^Infileincludedfrom/usr/include/c++/8.1.1/vector:64,fromBigSorting.cpp:2:/usr/include/c++/8.1.1/bits/stl_vector.h:1074:

c++ - std::shared_mutex 是否有利于作者而不是读者?

从C++17(C++14)开始,我们有了std::shared_(timed_)mutex类。很长一段时间以来,Qt都有一个类似的类QReadWriteLock。QReadWriteLock的documentation说:Toensurethatwritersaren'tblockedforeverbyreaders,readersattemptingtoobtainalockwillnotsucceedifthereisablockedwriterwaitingforaccess,evenifthelockiscurrentlyonlyaccessedbyotherreaders.A

c++ - std::function 在堆栈数组中使用时崩溃

在MSVisualC++2010SP1中,此代码崩溃:#include"stdafx.h"#include#include//#includeinta=0;int_tmain(intargc,_TCHAR*argv[]){//thiswayitworks://std::vector>s;//s.push_back([](){a=1;});//s.push_back([](){a=2;intb=a;});std::functions[]={[](){a=1;},[](){a=2;//Problemoccursonlyifthefollowinglineisincluded.Whencom

c++ - 我的函数应该返回一个指向 std::vector 的指针,还是一个对 std::vector 的引用?

我有一个std::map>,并提供类似std::vectorFindData(intkey)的查询.为了防止复制整个数据,我将其修改为std::vector&FindData(intkey).但是,一定会没有数据key,所以有时我没有什么可返回的。在那种情况下,我声明一个空的文件范围变量std::vector并归还。但是如果我选择指向vector的指针,那就是std::vector*FindData(intkey)然后我可以返回NULL对于不存在的key.哪个更好?我了解到指向std::vector的指针在问题(Isthereothersyntaxforthispointeropera

c++ - 为什么将 T 从外部模板作为默认参数传递给 std::function 会导致编译错误?

我创建了一个模板类,并将T作为默认类型参数传递。但是,这会导致编译失败。任何人都可以解释发生了什么?谢谢!附言。我使用的编译器是VS2012。#includeusingnamespacestd;templatestructdelegate{typedeffunctionfunction_t;function_tf;};intmain(){delegated;return0;}编译器输出:1>.\MicrosoftVisualStudio11.0\VC\include\functional(554):errorC2027:useofundefinedtype'std::_Get_func

c++ - std::vector 的 std::functions 查找

我有一个填充有回调函数的vector,我想在添加之前检查是否已经存在回调函数。我不知道它是否会工作,但到目前为止它甚至无法编译。vector>_callbacks;voidEvent::RegisterCallback(std::functioncallback){if(callback==NULL)return;vector>::iteratorit=std::find(_callbacks.begin(),_callbacks.end(),callback);if(it==_callbacks.end()){_callbacks.push_back(callback);}else{

c++ - std::bind 到 std::function 使用 Clang 崩溃

在将std::bind与std::function组合时,我无法理解一些细微之处。我已将我的问题最小化为以下代码片段:#include#includevoidbar(intx){std::coutf1=std::bind(bar,std::placeholders::_1);//CRASHESwithclang,worksfineinVS2010andVS2012std::functionf2=std::bind(f1,1);f2();return0;}注意到std::function的显式转换(在构建std::function时将auto替换为f2效果很好)。正在创建f2通过复制f1

c++ - 如何在 QtCreator 的调试器中显示 std::multimap 和 std::multiset 的内容?

我正在尝试检查std::multimap和std::multiset的内容QtCreator。我显示的不是值列表,而是实现细节。奇怪的是std::map和std::set对应项显示正常:#include#include#include#includeintmain(){std::multimapmultimap;multimap.insert(std::make_pair(1,"one"));multimap.insert(std::make_pair(2,"two"));multimap.insert(std::make_pair(3,"three"));std::multisetm

c++ - 我怎样才能让我的对象重新解释为数组,比如 std::complex?

我是因为thisquestion才知道这个的,标准规定为std::complex(26.4[复数]):4Ifzisanlvalueexpressionoftypecvstd::complexthen:—theexpressionreinterpret_cast(z)shallbewell-formed,—reinterpret_cast(z)[0]shalldesignatetherealpartofz,and—reinterpret_cast(z)[1]shalldesignatetheimaginarypartofz.Moreover,ifaisanexpressionoftype

c++ - 当 -std=c++11 选项被删除时,clang++ 仅使用 boost::format 编译 C++11 程序

请看下面的C++11片段:#includeintmain(intargc,char**argv){autos=boost::format("");return0;}当我使用-std=c++11用clang编译它时,我得到以下错误:$clang++-std=c++11-omainmain.cppInfileincludedfrommain.cpp:1:Infileincludedfrom/usr/include/boost/format.hpp:19:Infileincludedfrom/usr/include/boost/detail/workaround.hpp:41:Infilei