add polymorphism

This commit is contained in:
lucaspalomodevelop 2022-11-11 12:14:42 +01:00
parent e254149b8d
commit 6e2edbdd96
5 changed files with 15 additions and 19 deletions

View File

@ -1,6 +1,5 @@
#ifndef TIER_H // ensuring that this object is only initialized once
#include "tier.cpp"
#endif
class hund : public tier
{

View File

@ -1,6 +1,5 @@
#ifndef TIER_H //ensuring that this object is only initialized once
#include "tier.cpp"
#endif
class katze : public tier
{

View File

@ -1,12 +1,21 @@
#include "hund.cpp"
#include "katze.cpp"
#include "tier.cpp"
#include <stdio.h>
#include <iostream>
#include <string>
int main(){
katze a;
std::string laut = a.getLaut();
std::cout << laut << std::endl;
int main()
{
tier arr[2];
arr[0] = katze();
arr[1] = hund();
for (size_t i = 0; i < 2; i++)
{
std::string laut = arr[i].getLaut();
std::cout << laut << std::endl;
}
return 0;
}

Binary file not shown.

View File

@ -4,17 +4,6 @@
#include <string>
#include "tier.h"
// class tier
// {
// public:
// tier();
// std::string getLaut();
// protected:
// std::string Laut;
// };
tier::tier()
{
this->Laut = "void";