getting error: neljastest.cpp: undefined reference to Vector2::Vector2(float, float)
neljastest.cpp:
#include <cstdlib>
#include <iostream>
#include "../include/Vector2.h"
#include "../include/neljas.h"
using namespace std;
int main (int argc, char* argv[]) {
Vector2 p1 (1.0, 2.0);
Vector2 p2 (0.0, 0.0);
Vector2 p3 (5.0, 2.0);
return EXIT_SUCCESS;
}
vector2.h:
#ifndef VECTOR2_H
#define VECTOR2_H
#include <iostream>
using std::ostream;
class Vector2 {
public:
float x;
float y;
Vector2();
Vector2(float nx, float ny);
float distanceFrom(Vector2 v);
};
ostream& operator << (ostream& valja, Vector2 v);
#endif
vector2.cpp:
#include "../include/Vector2.h"
#include <cmath>
using namespace std;
Vector2::Vector2() {
x = 0;
y = 0;
}
Vector2::Vector2(float nx, float ny) {
x = nx;
y = ny;
}
float Vector2::distanceFrom(Vector2 v) {
return sqrt( (x - v.x)*(x - v.x) + (y - v.y)*(y - v.y) );
}
ostream& operator << (ostream& os, Vector2 v) {
return os << "(" << v.x << "," << v.y << ")";
}
C/C++ are case sensitive for headers too.
It seems that on vector2.cpp and neljastest.cpp you must change the include from:
To:
I pasted all your sources on the same folder and successfully compiled them with:
Edit:
Your problem is that the linking process of neljastest.cpp depends on src/vector2.cpp, and you are not doing that on the Makefile