| Paste number 90539: | c++code |
| Pasted by: | mun |
| When: | 8 months, 1 week ago |
| Share: | Tweet this! | http://paste.lisp.org/+1XUZ |
| Channel: | None |
| Paste contents: |
#include "stdafx.h"
#include "stdio.h"
#include <iostream>
using namespace std;
class Animal
{
public:
virtual void eat(bool z)= 0;
int func1()
{
int x = 1;
eat( true);
return x;
}
};
class Dog : public Animal
{
public:
void eat(bool z)
{
cout<<"I eat like a dog"<<endl;
}
};
class Cat : public Animal
{
public:
void eat(bool z)
{
cout<<"I eat like a cat"<<endl;
}
};
class dosomething
{
public:
void func2()
{
//I want this type of functionality
Animal* z = new Cat;
z->func1(); // it will print "I eat like a cat"
z = new Dog;
z->func1(); // it will print "I eat like a Dog"
}
};
int _tmain(int argc, _TCHAR* argv[])
{
dosomething n1;
n1.func2();
return 0;
}
This paste has no annotations.