2

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.

#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
  • 119
  • 1
  • 1
  • 10

3 Answers3

1

It looks like your Copy and Concat functions 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:

String Copy(char* orig)
{
    // Same copy logic you have, 
    // except copy into "*this"
}
Dagrooms
  • 1,507
  • 2
  • 16
  • 42
  • Would you mind expanding on "*this" a little. I am trying to make the change and am getting an error that says "expression must be a modifiable lvalue. – K455306 Apr 24 '16 at 04:39
  • Google your errors? Best I can think of is this http://stackoverflow.com/questions/6008733/expression-must-be-a-modifiable-l-value – Dagrooms Apr 25 '16 at 04:51
0

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.

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

-1

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

String(char *);

  • And String s1 = "Howdy"; String s2 = " there"; Also needs the construction function above. once you provided, the error should be eliminated. – shiningstarpxx Apr 22 '16 at 03:58