Hello everybody!
I'm trying to understand following code.
#include "stdafx.h"
#include <iostream>
using namespace std;
class Circle;
class Square;
class Triangle;
class Shape {
public:
virtual bool Check(const Shape&)const = 0;
virtual bool Check(const Circle&)const = 0;
virtual bool Check(const Square&)const = 0;
virtual bool Check(const Triangle&)const = 0;
};
class Circle : public Shape {
public:
bool Check(const Shape& s)const
{return s.Check(*this);}
bool Check(const Circle&)const
{cout << "Circle & Circle\n"; return true;}
bool Check(const Square&)const
{cout << "Circle & Square\n"; return true;}
bool Check(const Triangle&)const
{cout << "Circle & Triangle\n"; return true;}
};
class Square : public Shape {
public:
bool Check(const Shape& s) const
{return s.Check(*this);}
bool Check(const Circle& c)const
{return c.Check(*this);}
bool Check(const Square&)const
{cout << "Square & Square\n"; return true;}
bool Check(const Triangle&)const
{cout << "Square & Triangle\n"; return true;}
};
class Triangle : public Shape {
public:
bool Check(const Shape& s)const{return s.Check(*this);}
bool Check(const Circle& c)const{return c.Check(*this);}
bool Check(const Square& s)const{return s.Check(*this);}
bool Check(const Triangle&)const
{cout << "Triangle & Triangle\n"; return true;}
};
bool intersect(const Shape& s,const Shape& t)
{return s.Check(t);}
int _tmain(int argc, _TCHAR* argv[])
{
Circle c;
Square s;
Triangle t;
intersect(c,s);
intersect(t,c);
intersect(s,t);
intersect(t,t);
system("PAUSE");
return 0;
}
What I don't understand is: the second "const", that is using before every Check's body function like: bool Check(const Shape& s)const{return s.Check(*this);}.
I can not find something similar to this in my ebooks.
So I need your helps.
Thanks in advanced!