Hello everybody, I am a beginner in c++! I'am doing an exercice but I have a problem that i can't solve. I'm trying to create a new class witch allows me to create a point in 2D with two different methods.My file's name is cdm.C and this is my code:
#include<iostream>
using namespace std;
class Point
{
public:
double X;
double Y;
Point(double n,double m)
{
X=n;
Y=m;
cout<<"Point constructor"<<endl;
}
~Point()
{
cout<<"Point distructor"<<endl;
}
void Print()
{
cout<<"Point P("<<X<<","<<Y<<")"<<endl;
}
};
int main()
{
Point P1(4.5,5.7);
Point P2;
P2.X=3.1;
P2.Y=2.5;
P1.Print();
P2.Print();
return 0;
}
and this is the error message from the terminal:
cdm.C: In function ‘int main()’:
cdm.C:27: error: no matching function for call to ‘Point::Point()’
cdm.C:8: note: candidates are: Point::Point(double, double)
cdm.C:4: note: Point::Point(const Point&)
[code] Your code goes here [/code] Point P2; Here you are using the default constructor of the class. However, you never implement it (if you provide another constructor, the compiler doesn't do the default for you)