не определено ссылка на `cs_mystring::MyString::operator=(cs_mystring::MyString const&)'|
неопределенная ссылка на `cs_mystring::MyString::MyString(cs_mystring::MyString const&)' |
Вот мой файл заголовка:
Код: Выделить всё
#ifndef MYSTRING_H
#define MYSTRING_H
#include
#include // for toupper()
#include
#include
#include
using namespace std;
namespace cs_mystring
{
class MyString
{
public:
static const int MAX_INPUT_SIZE = 127;
int length() const;
MyString(); // default constructor
MyString(const char* inString); // parameterized constructor
friend std::ostream& operator > (std::istream& in, MyString& readMe);
void readline(std::istream& in, char delimeter); //another setter type function
char operator[] (int index) const;
char& operator [] (int index);
friend bool operator < (const MyString& leftOp, const MyString& rightOp);
friend bool operator (const MyString& leftOp, const MyString& rightOp);
friend bool operator >= (const MyString& leftOp, const MyString& rightOp);
friend bool operator == (const MyString& leftOp, const MyString& rightOp);
friend bool operator != (const MyString& leftOp, const MyString& rightOp);
MyString operator += (const MyString& rightOp);
friend MyString operator + (const MyString& leftOp, const MyString& rightOp);
~MyString(); // class destructor
MyString operator=(const MyString& right); // = operator used in client code
MyString(const MyString& copyMe); //copy constructor makes a deep copy
private:
char *str;
};
}
#endif
Код: Выделить всё
#include "mystring.h"
#include
#include
#include
#include
#include
#include
using namespace std;
namespace cs_mystring
{
MyString::MyString() // default constructor
{
str = new char[1];
strcpy(str, "");
}
MyString::MyString(const char* inString) // parameterized constructor
{
str = new char[strlen(inString) + 1];
strcpy(str, inString);
}
MyString::~MyString()
{
delete [] str;
}
ostream& operator (std::istream& in, MyString& readMe)
{
delete[] readMe.str;
char tempString[MyString::MAX_INPUT_SIZE + 1];
in >> tempString;
readMe.str = new char[strlen(tempString) + 1];
strcpy(readMe.str, tempString);
return in;
}
void MyString::readline(std::istream& in, char delimeter)
{
char tempStr[MyString::MAX_INPUT_SIZE + 1];
in.getline(tempStr, MyString::MAX_INPUT_SIZE + 1, delimeter);
delete [] str;
str = new char[strlen(tempStr) + 1];
strcpy(str, tempStr);
}
int MyString::length() const
{
return strlen(str);
}
char MyString::operator[](int index)const
{
assert(index >= 0 && index < strlen(str));
return str[index];
}
char& MyString::operator[](int index)
{
assert(index >= 0 && index < strlen(str));
return str[index];
}
bool operator < (const MyString& leftOp, const MyString& rightOp)
{
return strcmp(leftOp.str, rightOp.str) < 0;
}
bool operator 0;
}
bool operator >= (const MyString& leftOp, const MyString& rightOp)
{
return strcmp(leftOp.str, rightOp.str) >= 0;
}
bool operator == (const MyString& leftOp, const MyString& rightOp)
{
return strcmp(leftOp.str, rightOp.str) == 0;
}
bool operator != (const MyString& leftOp, const MyString& rightOp)
{
return strcmp(leftOp.str, rightOp.str) != 0;
}
MyString operator + (const MyString& leftOp, const MyString& rightOp)
{
MyString tempString;
delete [] tempString.str;
tempString.str = new char[strlen(leftOp.str) + strlen(rightOp.str) + 1];
strcpy(tempString.str, leftOp.str);
strcat(tempString.str, rightOp.str);
return tempString;
}
MyString MyString::operator += (const MyString& rightOp)
{
*this = *this + rightOp;
return *this;
}
/*MyString MyString::operator=(const MyString& right)
{
if (this != &right)
{
delete[] str;
str = new char[strlen(right.str) + 1];
strcpy(str, right.str);
}
return *this;
} */
}
Код: Выделить всё
#include "mystring.h"
#include
#include
#include
#include
#include
using namespace std;
using namespace cs_mystring;
void BasicTest();
void RelationTest();
void ConcatTest();
void CopyTest();
MyString AppendTest(const MyString& ref, MyString val);
string boolString(bool convertMe);
int main()
{
cout
Подробнее здесь: [url]https://stackoverflow.com/questions/61606099/error-with-overloading-operator-in-string-project[/url]
Мобильная версия