Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- // Class
- class Animal{
- public:
- int lifespan;
- Animal(){}
- Animal(int _lifespan){
- lifespan = _lifespan;
- }
- };
- // Inheritance
- class Dog : public Animal{
- public:
- string say;
- Dog(string _say) : Animal(20){
- say = _say;
- }
- };
- // Extension
- // void Dog::whine(){
- // cout << "*whine*" << endl
- // }
- // Apparently you can't do that in C++ unless it was already declared within the class
- //Instantiation
- int main(){
- Dog doggy("bark");
- cout << "Dog says " << doggy.say << endl;
- cout << "Dog's lifespan is " << doggy.lifespan << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement