Created
April 16, 2021 11:29
-
-
Save RichardB01/8169e54afd0ac482cffb7ee05a485f5a to your computer and use it in GitHub Desktop.
OOP without the heap
This file contains hidden or 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 <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