Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include "Constructors.h"
- using namespace std;
- int main() {
- Animal animal1;
- animal1.setName("Klinton");
- Animal animal2 = animal1;
- animal2.speak();
- animal2.setName("Freddy");
- animal2.speak();
- return 0;
- }
- #ifndef _CONSTRUCTORS_H_
- #define _CONSTRUCTORS_H_
- #include <string>
- class Animal {
- private:
- std::string name;
- public:
- Animal() { cout << "Animal created." << endl; }
- Animal(const Animal& other): name(other.name) { cout << "Animal created copying." << endl; }
- void setName(std::string name) { this->name = name; }
- void speak() const { cout << "My name is: " << name << endl; }
- }
- #endif // !_CONSTRUCTORS_H_
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement