PossibleDuplicate:std::bindoverloadresolution考虑以下C++示例classA{public:intfoo(inta,intb);intfoo(inta,doubleb);};intmain(){Aa;autof=std::async(std::launch::async,&A::foo,&a,2,3.5);}这给出了“std::async”:无法推断模板参数,因为函数参数不明确。我该如何解决这种歧义?? 最佳答案 帮助编译器解决歧义,告诉你想要哪个重载:std::async(std::la
我正在为具有不同数据结构和技术(vector、数组和OpenMP)的矩阵实现C++乘法,我发现了一个奇怪的情况……我的动态数组版本运行得更好:次数:openmpmult_1:time:5.882000sarraymult_2:time:1.478000s我的编译标志是:/usr/bin/g++-fopenmp-pthread-std=c++1y-O3C++vector版typedefstd::vector>matrix_f;voidmult_1(constmatrix_f&matrixOne,constmatrix_f&matrixTwo,matrix_f&result){consti
因为我无法找到这样的函数(不正确?),我正在尝试创建一个编译时函数(constexpr)函数,它接受std::arrayarr。和一个Tt并返回一个新的std::array与t添加到arr的末尾.我从这样的事情开始:templateconstexprstd::arrayappend(std::arraya,Tt);templateconstexprstd::arrayappend(std::arraya,Tt){returnstd::array{t};}templateconstexprstd::arrayappend(std::arraya,Tt){returnstd::array{
我在为给定类型创建函数时遇到问题,如果它是从其他类型派生的,那么它会做某事,而对于所有其他情况,则做其他事情。我的代码:classBaseClass{};classDerivedClass:publicBaseClass{};templatevoidFunction(typenamestd::enable_if::value,T>::type&&arg){std::coutvoidFunction(T&&arg){std::cout对于DeriviedClass类和其他基于BaseClass的类,我想调用函数coutingProper,但是它couts不正确。有什么建议吗?
我有以下模板。templatestd::vectormap(conststd::vector&v,std::functionf){std::vectorres;res.reserve(v.size());std::transform(std::begin(v),std::end(v),std::end(res),f);returnres;}当我在我的代码中使用它时,我指定了模板参数。为什么编译器不能为我推断出这个?我必须如何更改我的模板定义才能使其正常工作?vectornumbers={1,3,5};//vectorstrings=map(numbers,[](intx){return
我刚刚使用mingw-get-setup更新了MinGW而且我无法构建包含的任何内容header如果我使用大于-O0的东西与-std=c++1y.(我也试过c++11和c++98)我收到这样的错误:g++.exe-pedantic-errors-pedantic-Wextra-Wall-std=c++1y-O3-cZ:\Projects\C++\L6\src\events.cpp-oobj\src\events.oInfileincludedfromz:\lander\mingw\lib\gcc\mingw32\4.8.1\include\c++\cmath:44:0,fromZ:\P
例如,我想使用类型T仅当std::is_pointer和std::is_const评估为true_type.当然还有一个简单的方法是这样的:templatevoidf(Tt,std::true_type,std::true_type){}templatevoidf(Tt){f(t,std::is_pointer{},std::is_const{});}但是我想要这样的东西:templatevoidf(Tt,std::true_type){}templatevoidf(Tt){f(t,std::and,std::is_const>{});}标准库是否包含类似std::and的内容??如果
请注意,这不是StackOverflow上有关gcc的许多问题的重复,我使用的是VisualStudio2013。这个正则表达式的简单构造会抛出std::regex_error:boolcaseInsensitive=true;charpattern[]="\\bword\\b";std::regexre(pattern,std::regex_constants::ECMAScript|(caseInsensitive?std::regex_constants::icase:0));what在异常对象上返回的实际错误是不一致的。通常它是不匹配的括号或括号。为什么?
我很好奇为什么我不能编译下面的代码。这是无意义的代码(我知道),但我最初在其他一些使用具有完美转发等模板的代码中遇到了这个问题。我设法将问题缩小到std::move/std::forward/std::remove_reference,并且我'我很好奇为什么它首先需要一个临时的...#include#includestructFoo{Foo(Foo&&other){printf("Foo::(Foo&&)%p\n",this);}Foo(){printf("Foo::()%p\n",this);}~Foo(){printf("Foo::~Foo()%p\n",this);}};void
那里发生了什么?#includenamespaceA{structClass{};}booloperator()(A::Class(),A::Class());return0;}这是编译好的。但如果我使用。#include我有错误:g++test.cc-otestInfileincludedfrom/usr/lib/gcc/x86_64-pc-linux-gnu/4.5.2/include/g++-v4/bits/stl_tree.h:64:0,from/usr/lib/gcc/x86_64-pc-linux-gnu/4.5.2/include/g++-v4/set:60,fromlo