I've created very simple C++ project in codeblocks. I have header file (CVector.h), source file (CVector.cpp) and main code (code.cpp). When I try to compile the code I got the following message:
CVector.cpp|22|error: no matching function for call to 'CVector::CVector()'|
code.cpp
#include <iostream>
#include "CVector.h"
using namespace std;
int main () {
CVector vec1(1,2);
CVector vec2 (3,4);
cout << "vec1 data "; vec1.printData();
cout << "vec2 data "; vec2.printData();
cout << "vec1 area: " << vec1.area() << endl;
cout << "vec2 area: " << vec2.area() << endl;
return 0;
}
CVector.h
#ifndef CVECTOR_H
#define CVECTOR_H
class CVector
{
int x,y;
public:
CVector (int, int);
int area();
void printData ();
CVector operator+ (CVector param );
};
#endif // CVECTOR_H
CVector.cpp
#include <iostream>
#include "CVector.h"
using namespace std;
CVector::CVector (int a, int b) {
x=a;
y=b;
}
int CVector::area() {return x*y;}
void CVector::printData(){
cout << "X = " << x << ", Y = " << y << endl;
}
CVector CVector::operator+ (CVector param )
{
CVector temp;
temp.x=x + param.x;
temp.y=y + param.y;
return temp;
}
The error is related to the operator overloading function because it compiles without problems when I comment this function.