#include "stdafx.h"
#include <iostream>
using namespace std;

class CPolygon
{
protected:
	int width, height;
public:
	void setup(int first, int second)
	{
		width = first;
		height = second;
	}
	virtual int area()
	{
		return (0);
	}
};


class CRectangle : public CPolygon
{
public:
	int area()
	{
		return (width * height);
	}
};

class CTriangle : public CPolygon
{
public:
	int area()
	{
		return (width * height / 2);
	}
};

int main()
{
	/*  Here we have class rectangle, triangle derived from polygon
	We declare pointers to polygon and assign them the derived objects.
	due to the fact we have used virtual functions, the compiler knows which object that the 
	base pointer is pointing to so it calls the appropriate function*/

	CRectangle rectangle;
	CTriangle triangle;
	CPolygon polygon;

	CPolygon * ptr_polygon1 = &rectangle;
	CPolygon * ptr_polygon2 = &triangle;
	CPolygon * ptr_polygon3 = &polygon;

	ptr_polygon1->setup(2, 2);
	ptr_polygon2->setup(2, 2);
	ptr_polygon3->setup(2, 2);

	cout << ptr_polygon1->area() << endl;
	cout << ptr_polygon2->area() << endl;
	cout << ptr_polygon3->area() << endl;
}