I was trying to write a header file in C++ which declares a class, but when I try to use the actual code it gives me the error "undefined reference" to the methods of the class in the header file; what should I do to fix it?
Class code
#include <iostream>
#include <Punto2D.h>
#include <math.h>
class Punto2D {
private:
int x;
int y;
public:
Punto2D() {
x = 0;
y = 0;
};
int get_x() {
return x;
};
};
Header file
#ifndef Punto2D_H
#define Punto2D_H
#include <iostream>
#include <math.h>
class Punto2D {
private:
int x;
int y;
public:
Punto2D();
int get_x();
};
#endif
Main file
#include <iostream>
#include "Punto2D.h"
using namespace std;
int main() {
Punto2D A;
cout << A.get_x();
}
At first, I though that it was because I forgot some part of the code so I tried some trouble shooting the thing that made me the closer to actually make the code work was adding to the header files methods the curly brackets but as far as I understand you shouldn't put them there.