Created
October 5, 2014 11:18
-
-
Save iluxonchik/27d8fa0ddaaeac6a9419 to your computer and use it in GitHub Desktop.
Everything works fine here
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "Animal.h" | |
#include <string> | |
#include<iostream> | |
Animal::Animal(int age, std::string name) : name(name), age(age) { } | |
Animal::~Animal() { } | |
void Animal::sleep(){ printf("Shhh! %s is sleeping...\n", this->name); } | |
bool Animal::operator==(const Animal &animal){ | |
return this->age == animal.age; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string> | |
class Animal | |
{ | |
private: | |
int age; | |
std::string name; | |
public: | |
Animal(int age, std::string name); | |
~Animal(); | |
void sleep(); | |
bool operator==(const Animal &animal); // the other animal is referenced by "this" | |
int getAge() const { return age; } | |
std::string getName() const { return name; } | |
}; | |
std::ostream &operator<<(std::ostream &o, const Animal &animal){ | |
return o << "Name: " << animal.getName() << " Age: " << animal.getAge(); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment