Skip to content

Instantly share code, notes, and snippets.

@iluxonchik
Created October 5, 2014 11:18
Show Gist options
  • Save iluxonchik/27d8fa0ddaaeac6a9419 to your computer and use it in GitHub Desktop.
Save iluxonchik/27d8fa0ddaaeac6a9419 to your computer and use it in GitHub Desktop.
Everything works fine here
#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;
}
#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