So i am learning how to use templates for the first time. I am trying to create simplified vector and point classes. Unfortunately i need to model that a point can be translated by a vector and a vector can be created due to the subtraction of two points.
The problem i am having is i need to include the files in each other. When I include my vector class in my point template header i get a compiler error because the Point class is no longer recognized as a template.
Vector Class (in Vector3D.h)
#include "Point3D.h"
template <class T>
class Vector3D
{
public:
//Members
T x,y,z;
... //more boring functions
Point3D<T> operator+ (const Point3D<T>& pt)
{
Point3D <T> pt2(x + pt.x, y + pt.y, z + pt.z);
return pt2;
}
};
Point Class (in Point3D.h)
#include "Vector3D.h"
template <class K>
class Point3D
{
public:
//Members
K x,y,z;
...//boring functions of little importance
// shifts point by a vector
Point3D<K> operator+ (const Vector3D<K>& other)
{
return Point3D<K>(x + other.x, y + other.y, z + other.z);
}
//creates a vector from the differnce between two points
Vector3D<K> operator- (const Point3D<K>& rhs)
{
return Vector3D<K>(x-lhs.x,y-lhs.y,z-lhs.z)
}
};
Now I get the following compiler errors (Intel C++ 15):
1>F:\Dev Repos\Vascular Modeling\Radiation Modeling Projects\CGAL BOOST INTEL project1\Vector3D.h(197): error : Point3D is not a template
1> Point3D<T> operator+ (const Point3D<T>& pt)
1> ^
1>
1>F:\Dev Repos\Vascular Modeling\Radiation Modeling Projects\CGAL BOOST INTEL project1\Vector3D.h(197): error : Point3D is not a template
1> Point3D<T> operator+ (const Point3D<T>& pt)
What am i doing wrong? I assume I am attempting to break the laws of physics and creating some kind of loop. Is the solution to make a split file implementation?
Thanks,
Will