Skip to content

Commit 90c1ee1

Browse files
committed
ensure there is no slicing risk on inherited classes
1 parent 512e416 commit 90c1ee1

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

Circleoutline.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#include <opencv2/opencv.hpp>
2727
#include <QJsonObject>
2828
void fillCircle(cv::Mat &m, double cx, double cy, double rad, void *color);
29-
class CircleOutline: public boundary
29+
class CircleOutline final: public boundary
3030
{
3131
public:
3232
CircleOutline();
@@ -35,7 +35,7 @@ class CircleOutline: public boundary
3535
CircleOutline(const QJsonObject &obj);
3636
void toJson(QJsonObject &obj);
3737

38-
virtual ~CircleOutline();
38+
~CircleOutline();
3939
void draw(QPainter& painter, double scale, double scale2 = -1.);
4040
bool isInside(QPointF& p , int offset = 0);
4141
bool isInside(double x, double y, int offset=0);
@@ -48,17 +48,15 @@ class CircleOutline: public boundary
4848
double m_radius;
4949
gPlus m_p1;
5050
gPlus m_p2;
51-
protected:
52-
53-
private:
5451
};
5552

56-
class ellipseOutline: public boundary
53+
class ellipseOutline final: public boundary
5754
{
5855
public:
5956
ellipseOutline();
6057
ellipseOutline(QPointF center, double minorAxis, double majorAxis);
6158
ellipseOutline(QPointF left, QPointF right, double ecc);
59+
void draw(QPainter& painter, double scale, double scale2 = -1.);
6260
bool isInside(QPointF& p , int offset = 0);
6361
void enlarge(int del);
6462
void translate(QPointF del);
@@ -76,11 +74,12 @@ class ellipseOutline: public boundary
7674
gPlus m_p2;
7775
};
7876

79-
class rectangleOutline: public boundary
77+
class rectangleOutline final: public boundary
8078
{
8179
public:
8280
rectangleOutline();
8381
rectangleOutline(QPointF upperLeft, QPointF lowerRight);
82+
void draw(QPainter& painter, double scale, double scale2 = -1.);
8483
bool isInside(QPointF& p , int offset = 0);
8584
void enlarge(int del);
8685
void translate(QPointF del);

boundary.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,26 @@
1818
#ifndef BOUNDARY_H
1919
#define BOUNDARY_H
2020
#include <QPainter>
21+
22+
// asbtract base class. Zero risk of slicing.
2123
class boundary
2224
{
25+
protected:
26+
boundary() = default;
27+
~boundary() = default;
28+
// Copy operations
29+
boundary(const boundary&) = default;
30+
boundary& operator=(const boundary&) = default;
31+
// Move operations
32+
boundary(boundary&&) noexcept = default;
33+
boundary& operator=(boundary&&) noexcept = default;
2334
public:
24-
virtual ~boundary() {}
2535
virtual void draw(QPainter& painter, double scale, double scale2 = -1.) = 0;
2636
virtual void enlarge(int del) = 0;
2737
virtual void translate(QPointF del) = 0;
2838
virtual void scale(double factor) = 0;
2939
virtual bool isValid() = 0;
3040
virtual bool isInside(QPointF& p, int offset = 0) = 0;
31-
protected:
3241
private:
3342
};
3443
QDataStream & operator<<(QDataStream & stream, const boundary &outline);

gplus.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class gPlus
2424
public:
2525
gPlus(QPointF p);
2626
gPlus();
27-
virtual ~gPlus();
27+
~gPlus();
2828
void draw(QPainter& dc, double scale, int size = 10);
2929
QPointF m_p;
3030
protected:

0 commit comments

Comments
 (0)