Created
April 9, 2021 03:32
-
-
Save cms-codes/821e93b13b07df30b19e4221ead698a4 to your computer and use it in GitHub Desktop.
This file contains 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> | |
#include <string> | |
#include <assert.h> | |
class Animal | |
{ | |
public: | |
double age; | |
}; | |
class Pet | |
{ | |
public: | |
std::string name; | |
}; | |
// Dog derives from *both* Animal and Pet | |
class Dog : public Animal, public Pet | |
{ | |
public: | |
std::string breed; | |
}; | |
// Cat also derives from both Animal and Pet | |
// but the constructor assignment does not see its inherited fields | |
class Cat : public Animal, public Pet | |
{ | |
public: | |
Cat(double age, std::string name, std::string color) | |
: age(age), name(name), color(color) | |
{} | |
std::string color; | |
}; | |
int main() | |
{ | |
Cat cat(10, "Max", "black"); | |
assert(cat.color == "black"); | |
assert(cat.age == 10); | |
assert(cat.name == "Max"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment