Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- class Dog {
- private:
- char* name;
- char* breed;
- int age;
- public:
- Dog(const char* dName = "", const char* dBreed = "", int dAge = 0);
- Dog(const Dog&);
- Dog& operator=(const Dog&);
- ~Dog();
- };
- int main() {
- return 0;
- }
- Dog::Dog(const char * dName, const char * dBreed, int dAge)
- {
- name = new char(strlen(dName) + 1);
- strcpy(name, dName);
- breed = new char(strlen(dBreed) + 1);
- strcpy(breed, dBreed);
- age = dAge;
- }
- Dog::Dog(const Dog &other)
- {
- name = new char(strlen(other.name) + 1);
- strcpy(name, other.name);
- breed = new char(strlen(other.breed) + 1);
- strcpy(breed, other.breed);
- age = other.age;
- }
- Dog & Dog::operator=(const Dog &other)
- {
- if (this != &other) {
- delete[] name;
- delete[] breed;
- name = new char(strlen(other.name) + 1);
- strcpy(name, other.name);
- breed = new char(strlen(other.breed) + 1);
- strcpy(breed, other.breed);
- age = other.age;
- }
- return *this;
- }
- Dog::~Dog()
- {
- delete[] name;
- delete[] breed;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement