consolidate all repos to one for archive
This commit is contained in:
30
semester_2/programiranje_2/primeri/Example34/CPoint.h
Normal file
30
semester_2/programiranje_2/primeri/Example34/CPoint.h
Normal file
@@ -0,0 +1,30 @@
|
||||
#ifndef EXAMPLE34_CPOINT_H
|
||||
#define EXAMPLE34_CPOINT_H
|
||||
|
||||
#include <iostream>
|
||||
#include "Point.h"
|
||||
|
||||
class CPoint : public Point {
|
||||
private:
|
||||
int color;
|
||||
public:
|
||||
CPoint() : Point(), color(0) {
|
||||
}
|
||||
CPoint(int x1, int y1, int b) : Point(x1, y1), color(b) {
|
||||
}
|
||||
~CPoint() {
|
||||
}
|
||||
bool equal(Point& p) {
|
||||
std::cout << "Method CPoint::equal(Point)" << std::endl;
|
||||
return true;
|
||||
}
|
||||
bool equal(CPoint& cp) {
|
||||
std::cout << "Method CPoint::equal(CPoint)" << std::endl;
|
||||
if ( (this->x==cp.x) && (this->y == cp.y) && (this->color == cp.color))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
#endif //EXAMPLE34_CPOINT_H
|
25
semester_2/programiranje_2/primeri/Example34/Point.h
Normal file
25
semester_2/programiranje_2/primeri/Example34/Point.h
Normal file
@@ -0,0 +1,25 @@
|
||||
|
||||
#ifndef EXAMPLE34_POINT_H
|
||||
#define EXAMPLE34_POINT_H
|
||||
#include <iostream>
|
||||
|
||||
class Point {
|
||||
protected:
|
||||
int x, y;
|
||||
public:
|
||||
Point() : x(0), y(0) {
|
||||
}
|
||||
Point (int x, int y) : x(x), y(y) {
|
||||
}
|
||||
~Point() {
|
||||
}
|
||||
virtual bool equal(Point& p) {
|
||||
std::cout << "Method Point::equal(Point)" << std::endl;
|
||||
if ((this->x==p.x) && (this->y == p.y))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
#endif //EXAMPLE34_POINT_H
|
29
semester_2/programiranje_2/primeri/Example34/main.cpp
Normal file
29
semester_2/programiranje_2/primeri/Example34/main.cpp
Normal file
@@ -0,0 +1,29 @@
|
||||
#include <iostream>
|
||||
#include "Point.h"
|
||||
#include "CPoint.h"
|
||||
|
||||
int main() {
|
||||
Point* t1 = new Point(1,1);
|
||||
Point* t2 = new CPoint(1,1,2);
|
||||
CPoint* t3 = new CPoint(2,2,2);
|
||||
|
||||
std::cout << t1->equal(*t1) << std::endl;
|
||||
std::cout << t1->equal(*t2) << std::endl;
|
||||
std::cout << t1->equal(*t3) << std::endl;
|
||||
std::cout << "-------------------" << std::endl;
|
||||
/*
|
||||
std::cout << t2->equal(*t1) << std::endl;
|
||||
std::cout << t2->equal(*t2) << std::endl; // static type is checked for parameters
|
||||
std::cout << t2->equal(*t3) << std::endl; // overloading is resolved during compile time
|
||||
std::cout << "-------------------" << std::endl;
|
||||
|
||||
std::cout << t3->equal(*t1) << std::endl;
|
||||
std::cout << t3->equal(*t2) << std::endl;
|
||||
std::cout << t3->equal(*t3) << std::endl; // overloaded method hide overridden method
|
||||
std::cout << "-------------------" << std::endl;
|
||||
*/
|
||||
delete t1;
|
||||
delete t2;
|
||||
delete t3;
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user