Salve,
a quanto pare riesco a individuare un bug in un compilatore
c++ ma non ad allegare un file ad un messaggio (...nessuno è
perfetto). Quindi aggiungo il codice in coda a questo messaggio:
TIA
1) *** header file ***
// Header
//
#ifndef EX_04_0013_H
#define EX_04_0013_H
struct Point
{
int x;
int y;
};
class CPoint
{
private:
Point p;
public:
CPoint();
~CPoint();
void set(Point);
void draw(void) const;
};
class CLine
{
private:
Point p1;
Point p2;
public:
CLine();
~CLine();
void set(Point, Point);
void draw(void) const;
};
class CDraw : public CPoint, public CLine
{
private:
public:
CDraw();
~CDraw();
void draw(void) const;
};
#endif // EX_04_0013_H
2) *** c++ file ***
// Inherited sample
//
#include <iostream>
#include "Ex_04_0013.h"
using namespace std;
CPoint::CPoint(void)
{
cout << "-> CPoint" << endl;
p.x = 0;
p.y = 0;
}
CPoint::~CPoint(void)
{
cout << "<- CPoint" << endl;
}
void CPoint::set(Point pt)
{
p.x = pt.x;
p.y = pt.y;
}
void CPoint::draw(void) const
{
cout << "CPoint draw" << endl;
}
CLine::CLine()
{
cout << "-> CLine" << endl;
p1.x = 0;
p1.y = 0;
p2.x = 0;
p2.y = 0;
}
CLine::~CLine()
{
cout << "<- CLine" << endl;
}
void CLine::set(Point pt1, Point pt2)
{
p1 = pt1;
p2 = pt2;
}
void CLine::draw(void) const
{
cout << "CLine draw" << endl;
}
CDraw::CDraw(void)
{
cout << "-> CDraw" << endl;
}
CDraw::~CDraw(void)
{
cout << "<- CDraw" << endl;
}
void CDraw::draw(void) const
{
cout << "CDraw draw" << endl;
}
void func1(CPoint& p)
{
Point x = {0,0};
p.set(x);
p.draw();
};
void func2(CLine& l)
{
Point x1 = {0,0};
Point x2 = {10,10};
l.set(x1,x2);
l.draw();
};
int main()
{
Point p = {1,1};
Point p1 = {1,20};
Point p2 = {10,20};
CPoint P;
P.set(p);
P.draw();
CLine L;
L.set(p1,p2);
L.draw();
CDraw d; // dreived <- public CPoint, public CLine
// Upcasting...
func1(d); // -> CPoint
func2(d); // -> CLine
CLine* ll = &d;
ll->draw(); // -> CLine
CPoint* pp = &d;
pp->draw(); // -> CPoint
CPoint& mm = d;
mm.draw(); // -> CPoint
CLine* lo;
lo = new CDraw();
lo->draw(); // -> CLine
delete lo;
CPoint* po;
po = new CDraw();
po->draw(); // -> CPoint
delete po;
cout << "*** THE CODE ***" << endl;
CDraw* dx;
dx->CPoint::draw();
dx->CLine::draw();
dx->draw();
}