Skip to content

Instantly share code, notes, and snippets.

@RichardB01
Created April 16, 2021 11:29
Show Gist options
  • Save RichardB01/8169e54afd0ac482cffb7ee05a485f5a to your computer and use it in GitHub Desktop.
Save RichardB01/8169e54afd0ac482cffb7ee05a485f5a to your computer and use it in GitHub Desktop.
OOP without the heap
#include <iostream>
class Mammal
{
public:
Mammal();
~Mammal();
};
class Dog : public Mammal
{
public:
Dog();
~Dog();
};
class Cat : public Mammal
{
public:
Cat();
~Cat();
};
class Zoo
{
public:
Zoo();
~Zoo();
void Add(Dog* d);
void Add(Cat* c);
private:
Dog* dogs[10];
Cat* cats[10];
};
Zoo zoos[10];
Dog dogs[10];
Cat cats[10];
int main()
{
Zoo* zoo = &(zoos[0]);
Dog* snoopy = &(dogs[0]);
Cat* savannah = &(cats[0]);
zoo->Add(snoopy);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment