C++ 没有重载函数的实例与参数列表匹配。

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36784443/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 14:38:13  来源:igfitidea点击:

No instance of overloaded function matches argument list.

c++

提问by K455306

I'm working on a project for class, but keep getting the error: no instance of overloaded function matches argument list. It is referencing my String classes. What I am trying to do is create a Copy, Concat and Count functions with out using the string class. Any help would be greatly appreciated.

我正在处理一个类项目,但不断收到错误消息:没有重载函数的实例与参数列表匹配。它引用了我的 String 类。我想要做的是创建一个 Copy、Concat 和 Count 函数而不使用字符串类。任何帮助将不胜感激。

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>

using namespace std;

class String
{
private:
char str[100]; 
char cpy[100];
public:

static const char NULLCHAR = '
String Copy(char* orig)
{
    // Same copy logic you have, 
    // except copy into "*this"
}
'; String() { str[0] = NULLCHAR; cpy[0] = NULLCHAR; } String(char* orig, char* cpy) { Copy(orig, cpy); } void Display() { cout << str << endl; } void Copy(char* orig, char* dest) { while (*orig != '##代码##') { *dest++ = *orig++; } *dest = '##代码##'; } void Copy(String& orig, String& dest) { Copy(orig.str, dest.cpy); } void Concat(char* orig, char* cpy) { while (*orig) orig++; while (*cpy) { *orig = *cpy; cpy++; orig++; } *orig = '##代码##'; } void Concat(String& orig, String& cpy) { Concat(orig.str, cpy.cpy); } int Length(char* orig) { int c = 0; while (*orig != '##代码##') { c++; *orig++; } printf("Length of string is=%d\n", c); return(c); } }; int main() { String s; s.Copy("Hello"); s.Display(); s.Concat(" there"); s.Display(); String s1 = "Howdy"; String s2 = " there"; String s3; String s4("This String built by constructor"); s3.Copy(s1); s3.Display(); s3.Concat(s2); s3.Display(); s4.Display(); system("pause"); return 0; }

回答by Dagrooms

It looks like your Copyand Concatfunctions each take two parameters, yet you pass them both a single parameter. If you want to copy them into a String object, your code should look more like:

看起来您的CopyConcat函数每个都有两个参数,但是您将它们都传递给一个参数。如果要将它们复制到 String 对象中,您的代码应该更像:

##代码##

回答by Aakash Arayambeth

As the error message says, There is no version of the constructor for your String class that takes a single parameter. You have a default constructor and one that takes two parameters.

正如错误消息所说,您的 String 类没有采用单个参数的构造函数版本。您有一个默认构造函数和一个带有两个参数的构造函数。

You need to define one which takes a single parameter and initializes the str

您需要定义一个接受单个参数并初始化 str

回答by shiningstarpxx

String s4("This String built by constructor"); this statement needs construction function

String s4("此字符串由构造函数构建"); 这个语句需要构造函数

String(char *);

字符串(字符*);