c++ダミーメソッド
6512 ワード
#include <iostream>
#include <string>
using namespace std;
class Pet
{
public:
Pet(string theName);
void eat();
void sleep();
virtual void play();
protected:
string name;
};
class Cat : public Pet
{
public :
Cat(string theName);
void climb();
void play();
};
class Dog : public Pet
{
public:
Dog(string theName);
void bark();
void play();
};
Pet::Pet(string theName)
{
name = theName;
}
void Pet::eat()
{
cout << name << "[ ]" << endl;
}
void Pet::sleep()
{
cout << name << "[ ]" << endl;
}
void Pet::play()
{
cout << name << "[ ]" << endl;
}
Cat::Cat(string theName) : Pet(theName)
{
}
void Cat::climb()
{
cout << name << "[ ]" << endl;
}
void Cat::play()
{
Pet::play();
cout << name << "[ ]" << endl;
}
Dog::Dog(string theName) : Pet(theName)
{
}
void Dog::bark()
{
cout << name << "[ ]" << endl;
}
void Dog::play()
{
Pet::play();
cout << name << "[ ]" << endl;
}
int main()
{
int *p = new int;
*p = 100;
cout << *p << endl;
delete p;
Pet *cat = new Cat(" ");
Pet *dog = new Dog(" ");
cat->sleep();
cat->eat();
cat->play();
dog->sleep();
dog->eat();
dog->play();
delete dog;
delete cat;
return 0;
}