Skip to content

Instantly share code, notes, and snippets.

@felladrin
Created February 10, 2012 21:18
Show Gist options
  • Save felladrin/1792957 to your computer and use it in GitHub Desktop.
Save felladrin/1792957 to your computer and use it in GitHub Desktop.
Herança simples
#include <iostream>
using namespace std;
class Animal
{
public:
Animal() {}
void respirar()
{
cout << "respirei";
}
void comer()
{
cout << "comi";
}
void reproduzir()
{
cout << "reproduzi";
}
};
class Gato : public Animal
{
public:
Gato() : Animal() {}
void respirar()
{
cout << "ronronei";
}
};
int main()
{
Animal a;
Gato g;
cout << "Animal.respirar(): ";
a.respirar();
cout << endl << "Animal.comer(): ";
a.comer();
cout << endl << "Animal.reproduzir(): ";
a.reproduzir();
cout << endl << "Gato.respirar(): ";
g.respirar();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment