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

新手上路,请多包涵

我正在开发一个类项目,但不断收到错误消息:没有重载函数的实例与参数列表匹配。它引用了我的 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 = '\0';

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 != '\0') {
        *dest++ = *orig++;
    }
    *dest = '\0';

}

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 = '\0';

}

void Concat(String& orig, String& cpy)
{
    Concat(orig.str, cpy.cpy);
}

int Length(char* orig)
{
    int c = 0;
    while (*orig != '\0')
    {
        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;
}

原文由 K455306 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 1.9k
1 个回答

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

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

原文由 Aakash Arayambeth 发布,翻译遵循 CC BY-SA 3.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题