草庐IT

If-None-Match

全部标签

C++ - 错误 E2285 : Could not find a match for 'tolower(char *)' in function parseInput(fstream &)

给定以下代码:voidparseInput(fstream&inputFile){constintLENGTH=81;charline[LENGTH];while(!inputFile.fail()){inputFile.getline(line,LENGTH);line=tolower(line);cout编译时出现这个错误:ErrorE2285:Couldnotfindamatchfor'tolower(char*)'infunctionparseInput(fstream&)我知道它返回一个int,而不是int[],这是否意味着我不应该使用getline而应该将输入字符转换为字符

c++ - 我怎样才能使 std::find_if 和 std::map 使用一些 boost 库协同工作?

这个问题的灵感来自anothertopic这提出了这个问题:Findthefirstvaluegreaterthanuserspecifiedvaluefromamapcontainer可以通过多种方式解决。典型的C++03解决方案定义了一个专用函数(或仿函数)并将其传递给std::find_if作为第三个参数。在C++11中,可以避免定义专用函数(或仿函数),而是可以使用lambda作为:autoit=std::find_if(m.begin(),mp.end(),[n](conststd::pair&x)->bool{returnx.second>n;});这是theaccepte

c++ - 成员函数的部分模板特化 : "prototype does not match"

我正在尝试部分特化一个非模板化类的模板化成员函数:#includetemplateclassFoo{};structBar{templateintfct(T);};templateintBar::fct(Foo){}intmain(){Barbar;Fooarg;std::cout我收到以下错误:c.cc:14:error:prototypefor‘intBar::fct(Foo)’doesnotmatchanyinclass‘Bar’c.cc:9:error:candidateis:templateintBar::fct(T)如何修复编译器错误? 最佳答案

c++ - if 语句中的函数名以一种奇怪的方式转换

使用此代码(有效的C++11):#include#includeboolmy_awesome_func(intparam){return(param>1);}intmain(intargc,charconst*argv[]){fprintf(stderr,"typeofmy_awesome_func:%s\n",typeid(my_awesome_func).name());if(my_awesome_func){fprintf(stderr,"WHAT???\n");}return0;}问题在if语句中。虽然typeid返回一些看起来像FbiE的东西(我认为这是函数类型的gcc语言)

C++ 模板实例化取决于 if 子句

目前我在做:if(dimension==2){typedefitk::ImageImageType;typedefitk::ImageIntegralImageType;m_pApp->train();}else{typedefitk::ImageImageType;typedefitk::ImageIntegralImageType;m_pApp->train();}但我想做的是:if(dimension==2)DIMENSION=2;elseDIMENSION=3;typedefitk::ImageImageType;typedefitk::ImageIntegralImageTy

c++ - `if constexpr`可以用来声明不同类型和init-expr的变量吗

例如:voidfoo(){ifconstexpr(...)intx=5;elsedoublex=10.0;bar(x);//callsdifferentoverloadsofbarwithdifferentvalues}这在D语言中很常见,但我没有找到有关C++17的信息。当然也可以用类似的东西std::conditional::typex;但仅限于基本情况。即使是不同的初始化程序(如上)也会造成大问题。 最佳答案 此代码无法运行。问题是当您调用bar时x超出范围。但有一个解决方法:constexprautot=[]()->auto

用于非类型模板参数的 c++ enable_if

我对部分模板特化有点困惑...我有一些代码依赖于算术数据类型T和小整数DIM。我希望能够为不同的DIM值指定不同的类方法。使用部分模板特化的不可能让我探索enable_if。这正是我所需要的……除了我希望它返回一个数字而不是一个类型。我怎样才能做到这一点?下面的代码应该说明我想要什么。#include#include#includetemplateclassfoo{public:Tfunction();};templateTfoo::value>::function(){//dosomethingreturn1.0;}templateTfoo::value>::function(){/

c++ - 如何将 enable_if 用于互斥的非成员函数模板?

我正在尝试编写非成员运算符函数模板,例如:#includetemplateclassMyType;templateautooperator==(MyTypeconst&l,MyTypeconst&r)->decltype(std::declval()==std::declval()){/*...*/}但是当我尝试处理l和r的长度不同时:template::type>autooperator==(MyTypeconst&l,MyTypeconst&r)->decltype(std::declval()==std::declval()){/*...*/}templateLu)>::type

c++ - 迭代器或指针的 std::enable_if 或 SFINAE

我想为MyClass编写一个带有参数的构造函数,并且我希望仅当参数是一个pointer或iterator(具有iterator_traits的东西)。如何实现? 最佳答案 遗憾的是,没有标准的方法来检测类是否为Iterator模型。最简单的检查是*it和++it在语法上都是有效的;您可以使用标准SFINAE技术执行此操作:template(),void(),++std::declval(),void())>MyClass(T);考虑到24.2.2:2中的Iterator要求:templatetypenamestd::enable_i

c++ - vector 迭代器 : no match for ‘operator=’

考虑到下面第一个代码片段中的C++代码,我得到了第二个代码片段中指示的编译错误。看起来我在遍历vector实例时做错了。你能告诉我如何克服这些编译问题吗?谢谢。代码中标记了LINE171。片段1(代码)#include#include#includeclassVipAddressSetEntity:BaseEntity{public:VipAddressSetEntity():BaseEntity(){}VipAddressSetEntity(std::string&uuid,std::string&name):BaseEntity(uuid,name){}VipAddressSetE