#include <iostream>
#include <cstring>
class MyString {
public:
// Constructor
MyString(const char* str);
// Copy constructor
MyString(const MyString& other);
// Destructor
~MyString();
// Getter function
const char* getStr() const;
private:
char* str;
};
// Constructor implementation
MyString::MyString(const char* s) {
str = new char[std::strlen(s) + 1];
std::strcpy(str, s);
}
// Copy constructor implementation
MyString::MyString(const MyString& other) {
str = new char[std::strlen(other.str) + 1];
std::strcpy(str, other.str);
}
// Destructor implementation
MyString::~MyString() {
delete[] str;
}
// Getter function implementation
const char* MyString::getStr() const {
return str;
}
int main() {
// Create an instance of MyString
MyString original("Hello, World!");
// Use the copy constructor to create a new instance
MyString copy(original);
// Display the strings
std::cout << "Original: " << original.getStr() << std::endl;
std::cout << "Copy: " << copy.getStr() << std::endl;
return 0;
}