草庐IT

string-comparison-functions

全部标签

c++ - 错误 : no '__________' member function declared in class '_______'

我认为自己是一个相当新手的c++程序员,我以前从未遇到过这个错误。我只是想为我的函数创建一个类,但我的头文件中声明的所有std::前缀函数都没有被识别//comments//comments//comments//comments//comments//comments//comments//comments//comments//comments//comments#ifndefPERSON_H#definePERSON_H#includeclassPerson{public:Person();std::stringgetName();//returnfirstnamestd::st

c++ - C++中使用String-To-Class Lookup table实例化类

寻找一种方法来避免大量IF/ELSE并使用查找表将字符串解析为特定类以进行实例化,所有这些类都派生自基类。这样的事情是否可能,如果可能,如何实现?typedefstructBaseClass{}BaseClass;typedefstructDerivedClassOne:BaseClass{}DerivedClassOne;typedefstructDerivedClassTwo:BaseClass{}DerivedClassTwo;typedefstruct{constchar*name;BaseClassclass;}LookupList;LookupListlist[]={{"C

C++11 auto、std::function 和对重载函数的模糊调用

我想知道是否有人知道为什么以下示例无法编译并给出对重载函数错误的模糊调用。如果我用强类型仿函数签名替换auto,它就能够正确区分两个方法重载。我注意到当不使用std::function作为我的重载参数时,不会发生同样的问题。如果我的重载只接受一个简单的float和int,即使使用auto关键字定义我的输入参数,编译器也可以正确区分这两个重载。我正在VisualStudio2012中编译它。这可能只是VS编译器中的错误吗?我现在无法访问装有GCC或Clang的机器,但有人知道这是否可以在那里编译吗?编译错误:对重载函数的调用不明确classAmbiguousOverload{public

c++ - strcmp 无法将 ‘std::string {aka std::basic_string<char>}’ 转换为‘const char*

这个问题在这里已经有了答案:strcmporstring::compare?(6个答案)关闭8年前。提前为问题的基本性质道歉。我正在尝试使用strcmp函数来测试两个字符串的匹配字符。我将问题简化为下面的简单代码:#include#includeusingnamespacestd;voidcompareStrings(string,string);intmain(){stringstring1="testString",string2="testString";compareStrings(string1,string2);return0;}voidcompareStrings(str

C++ 错误 : reference to non-static member function must be called

我正在尝试创建一个类来抽象libuv网络功能的一些基本行为。#defineTCP_BACKLOG256class_tcp{uv_tcp_t*tcp=NULL;public:~_tcp(){deletetcp;}voidlisten_uv_listen_uv_connection_cb(uv_stream_t*stream,intstatus){printf("NEWCONNECTION\n");}voidlisten(constchar*host,intport){tcp=newuv_tcp_t();uv_tcp_init(uv_default_loop(),tcp);sockaddr

c++ - 为什么 'control reaches end of non-void function' 只是一个警告?合法吗?

这个问题在这里已经有了答案:WhydoesthisC++snippetcompile(non-voidfunctiondoesnotreturnavalue)[duplicate](7个答案)关闭8年前。C++定义具有非void返回类型的函数允许控制到达函数末尾而不是到达return语句是否合法?gcc和clang仅为此发出警告。这样做的代码是合法的还是这些编译器只是慷慨?海湾合作委员会:warning:noreturnstatementinfunctionreturningnon-void[-Wreturn-type]clang:warning:controlreachesendof

c++ - 就地构建 std::function 目标

我所理解的std::function的典型用法#include#includeusingnamespacestd;classC{public:C(){coutf=C();f();return0;}产量如下输出CREATINGMOVECDELETINGCALLINGDELETING显然,临时对象是在堆栈上创建的,然后移入函数对象。如果未提供移动构造函数,则复制它。是否有无需临时对象即可设置目标的标准方法? 最佳答案 function由任何仿函数Ff构造的方式由§20.9.11.2.1中的标准规定为(假设f是一个非空值,强调我的):*t

c++ - 为什么 COW std::string 优化在 GCC 5.1 中仍然启用?

根据GCC5发布更改页面(https://gcc.gnu.org/gcc-5/changes.html):Anewimplementationofstd::stringisenabledbydefault,usingthesmallstringoptimizationinsteadofcopy-on-writereferencecounting我决定检查一下并写了一个简单的程序:intmain(){std::stringx{"blah"};std::stringy=x;printf("0x%X\n",x.c_str());printf("0x%X\n",y.c_str());x[0]=

c++ - 使用 std::string 调用类方法

假设我有以下类(class):(可能是元生成的)classMyClass{public:myMethod();...}这里假设一些事情:1.)Ihavetheclassnamefromsomewhere(let'spretend)2.)Ihavethenamesoftheclassmethodssomewhere(std::map...perhaps?)所以...因为我可能直到运行时才知道myMethod()的名称,有没有办法使用std::string调用它?这是假设我在某处存储了一个类函数的名称。MyClassexample;std::stringfuncName{findMyMet

c++ - 将 std::function<int(int)> 赋值给 std::function<const int&(const int& x)>

以下代码编译但在VC++2015(发行版)中产生未定义的输出和运行时错误othercompilers.#include#includeintmain(){std::functionf=[](intx){returnx;};std::functiong=f;std::cout为什么赋值g=f;是允许的? 最佳答案 考虑重写等效代码以避免lambda或std::function:intf(intx){returnx;}intconst&g(intconst&x){returnf(x);}这是一个结构良好的代码,尽管如此,它仍会返回一个对