I have encountered a problem, which is most likely caused by a wrong forward declaration of circular dependent classes. But forward declaring template classes (similar to here seems to still not work.
With visual studio express edition 2013 I get a LNK 4221 warning (no new symbols defined) which causes LNK 2019 (unresolved external symbol).
Here are the headers that cause problems:
3d vector
#ifndef VEC3_H
#define VEC3_H
// Standard library
#include <iostream>
#include <sstream>
// Internal
#include "SMath.h"
#include "Quaternion.h"
namespace Sapling {
template <typename T>
class Quaternion; ///< Forward
template <typename T> class Vec3 {
public:
// ...
void rotate(Vec3<T> axis, T radAngle) {
T sinHalfAngle = Math::sin(radAngle / 2);
T cosHalfAngle = Math::cos(radAngle / 2);
// Make a new quaternion [cos(w)|sin(w) vec]
Quaternion<T> rotation(axis.x * sinHalfAngle,
axis.y * sinHalfAngle,
axis.z * sinHalfAngle,
cosHalfAngle);
// Conjugate the rotation to eliminate the imaginary part
Quaternion<T> conjugate = rotation.getConjugate();
Quaternion<T> result = conjugate * (*this) * rotation; ///< frtl
x = result.x;
y = result.y;
z = result.z;
}
// ...
T x;
T y;
T z;
};
}
#endif
Quaternion
#ifndef QUATERNION_H
#define QUATERNION_H
// Standard library
#include <iostream>
#include <sstream>
// Internal
#include "Vec3.h"
namespace Sapling {
template <typename T>
class Vec3; ///< Forward
template <typename T> class Quaternion {
public:
// ...
Quaternion(Vec3<T> vec, T W) : x(vec.x), y(vec.y), z(vec.z), w(W) { }
// ...
// Relational vector operators
void operator*= (const Vec3<T>& v) {
x = -(x * v.x) - (y * v.y) - (z * v.z);
y = (w * v.x) + (y * v.z) - (z * v.y);
z = (w * v.y) + (z * v.x) - (x * v.z);
w = (w * v.z) + (x * v.y) - (y * v.x);
}
// ...
T x;
T y;
T z;
T w;
};
}
#endif ///< Include guard
I know the data of both classes should be private, but I couldn't get around to fix it so far...
So could you explain to me why this still results in circular dependencies?
Thanks and have a nice day :)