Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
4003CEM-inheritance/lab_animal1.h
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
42 lines (33 sloc)
912 Bytes
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
#ifndef LAB_ANIMAL_H // header guard | |
#define LAB_ANIMAL_H | |
#include <iostream> | |
#include <string> | |
/** Class of virtual animals. | |
* All animals have name, species, colour and id. | |
* Counter is class attribute counting number of Animals **/ | |
class Animal | |
{ | |
public: | |
// Class attribute to producing unique ids for each animal. | |
static int counter; | |
int id; | |
std::string name, species, colour; | |
Animal( std::string _name, std::string _species, std::string _colour ) | |
{ | |
id = counter; | |
counter += 1; | |
name = _name; | |
species = _species; | |
colour = _colour; | |
} | |
void wander() | |
{ | |
std::cout << name << " is wandering" << std::endl; | |
} | |
void display() | |
{ | |
std::cout << "A " << colour << " " << species << " called " << name << std::endl; | |
} | |
}; | |
int Animal::counter = 0; // remember to initialise the static attributes | |
#endif |