S
stephane
I can't make this work it says I dont have a default constructor available.
Can someone tell me what's wrong with this please?
#include <iostream>
using namespace std;
#include "points.h"
int main ()
{
Trectangle rec1(2,5,10,6);
Trectangle rec2(rec1);
return 0;
}
// points.h
#ifndef POINTS_H
#define POINTS_H
#include <iostream>
using namespace std;
class Tpoints{
public:
Tpoints(double x,double y):m_x(x),m_y(y)
{
cout<<"constr points 1"<<endl;
}
Tpoints(Tpoints& p)
{
m_x = p.m_x;
m_y = p.m_y;
cout<<"constr copie Tpoints"<<endl;
}
private:
double m_x;
double m_y;
};
class Trectangle{
public:
Trectangle(double x,double y, double larg, double haut)
: m_hautGauche(x,y), m_basDroite(x+larg, y+haut){cout<<"constr rec
1"<<endl;}
Trectangle(Trectangle& r)
{
cout<<"constr copie rec"<<endl;
m_hautGauche = r.m_hautGauche;
m_basDroite = r.m_basDroite;
}
// no appropriate default constructor available
private:
Tpoints m_hautGauche;
Tpoints m_basDroite;
};
#endif
Can someone tell me what's wrong with this please?
#include <iostream>
using namespace std;
#include "points.h"
int main ()
{
Trectangle rec1(2,5,10,6);
Trectangle rec2(rec1);
return 0;
}
// points.h
#ifndef POINTS_H
#define POINTS_H
#include <iostream>
using namespace std;
class Tpoints{
public:
Tpoints(double x,double y):m_x(x),m_y(y)
{
cout<<"constr points 1"<<endl;
}
Tpoints(Tpoints& p)
{
m_x = p.m_x;
m_y = p.m_y;
cout<<"constr copie Tpoints"<<endl;
}
private:
double m_x;
double m_y;
};
class Trectangle{
public:
Trectangle(double x,double y, double larg, double haut)
: m_hautGauche(x,y), m_basDroite(x+larg, y+haut){cout<<"constr rec
1"<<endl;}
Trectangle(Trectangle& r)
{
cout<<"constr copie rec"<<endl;
m_hautGauche = r.m_hautGauche;
m_basDroite = r.m_basDroite;
}
// no appropriate default constructor available
private:
Tpoints m_hautGauche;
Tpoints m_basDroite;
};
#endif