Why on earth is Xcode *&^% acting up???
I've been using Xcode for quite some time now, and I just installed it on my MacBook (I had it installed before, but I accidently erased my hard disk). Now I'm just trying to rewrite my game engine, so I started off with a simple cPoint2D class.
When I try to compile it, the linker keeps failing because "all the symbols in cPoint2D are undefined". I checked to make sure that cPoint2D.cpp was getting compiled, and it was. Then I tried moving all the code into main.cpp, and the problem went away. So, I figure this is more of a compiler issue than with my code, so I posted it here in the Tech Board.
But I just don't get it.......
Here is my code, just for you to observe:
Please do not criticize me for bad class design. This is a work in progress.
cPoint3D.h:
PHP Code:
// cPoint2D - basic class for 2D points
#ifndef CPOINT2D_H
#define CPOINT2D_H
#include <iostream>
using namespace std;
template <class T>
class cPoint2D {
public:
T x, y;
T operator*(cPoint2D<T> &value);
cPoint2D<T> operator+(cPoint2D<T> *value);
void print();
};
typedef cPoint2D<float> cfloat2D;
typedef cPoint2D<int> cint2D;
#endif
cPoint2D.cpp:
PHP Code:
// cPoint2D - basic class for 2D points
#include "cPoint2D.h"
template <class T>
T cPoint2D<T>::operator*(cPoint2D<T> &value) {
return x*(value->x) + y*(value->y);
}
template <class T>
cPoint2D<T> cPoint2D<T>::operator+(cPoint2D<T> *value) {
value->x += x;
value->y += y;
return value;
}
template <class T>
void cPoint2D<T>::print() {
cout << "cPoint2D: x=" << x << "; y=" << y << endl;
}
Basically, the compiler doesn't cough on this; it's just whenever I try to call any of the member functions from cPoint2D that I get a linker error saying that the function is undefined.