Would anyone know the reason for these errors...
///////////////////////////////////////////////////////////////////////////////
In file included from myInclude.h:7,
from main.cpp:1:
cl_3dPoint.h:81: error: expected init-declarator before '&' token
cl_3dPoint.h:81: error: expected `;' before '&' token
cl_3dPoint.h:36: warning: inline function `nmGeometric::cl_3dPoint<tType>& nmGeometric::cl_3dPoint<tType>::operator=(const nmGeometric::cl_3dPoint<tType>&) const [with tType = double]' used but never defined
make.exe: *** [main.o] Error 1
Execution terminated
///////////////////////////////////////////////////////////////////////////////
The following is my code, compiled with the mingw compiler system included with dev-c++. What is weird is that when I move the implementation of the overloaded assignment operator into the body of the class and remove the const keyword at the very end, it compiles perfectly. But when I try to do the same with the implemenation outside the class I get errors. Does anyone know why?
main.cpp
#include "myInclude.h"
using namespace nmGeometric;
int main()
{
// CONSTRUCTORS
cl_3dPoint < double > objPointB;
cl_3dPoint < double > objPointC(-2, 3, 8);
// ASSIGNMENT OPERATOR
objPointB = objPointC;
system("PAUSE");
return 0;
}
myInclude.h
#ifndef __MY_INCLUDE_H__
#define __MY_INCLUDE_H__
#include <iostream>
using namespace std;
#include "cl_3dPoint.h"
#endif // __MY_INCLUDE_H__
cl_3dPoint.h
#ifndef __CLASS_3D_POINT__
#define __CLASS_3D_POINT__
namespace nmGeometric
{
template <typename tType>
class cl_3dPoint
{
private:
protected:
public:
//
// MEMBER VARIABLES
//
tType x, y, z;
//
// MEMBER FUNCTIONS
//
// DESTRUCTOR
~cl_3dPoint();
// CONSTRUCTOR
cl_3dPoint();
// CONSTRUCTOR
cl_3dPoint(const tType & X, const tType & Y, const tType & Z);
// COPY CONSTRUCTOR
cl_3dPoint(const cl_3dPoint < tType > & param);
// =
inline cl_3dPoint & operator = (const cl_3dPoint < tType > & point_1) const;
}; // cl_3dPoint
// *************************************************************************
// DESTRUCTOR
// *************************************************************************
template < typename tType >
cl_3dPoint < tType >::~cl_3dPoint()
{
}
// *************************************************************************
// CONSTRUCTOR FOR A 3D POINT AT THE ORIGIN
// *************************************************************************
template < typename tType >
cl_3dPoint < tType >::cl_3dPoint(): x(static_cast < tType > (0)),
y(static_cast < tType > (0)),
z(static_cast < tType > (0)){}
// *************************************************************************
// CONSTRUCTOR FOR INITIALIZING A 3D POINT.
// *************************************************************************
template < typename tType >
cl_3dPoint < tType >::cl_3dPoint(const tType & X, const tType & Y, const tType & Z)
{
this->x = X;
this->y = Y;
this->z = Z;
}
// *************************************************************************
// COPY CONSTRUCTOR
// *************************************************************************
template < typename tType >
cl_3dPoint < tType >::cl_3dPoint(const cl_3dPoint < tType > & param) : x(param.x),
y(param.y),
z(param.z){}
// *************************************************************************
// =
// ASSIGNMENT OPERATOR. ASSIGNS ONE POINT TO ANOTHER
// *************************************************************************
template < typename tType >
inline cl_3dPoint & cl_3dPoint < tType >::operator = (const cl_3dPoint < tType > & point_1) const
{
// MAKE SURE THERE IS NO SELF ASSIGNMENT OF THE SAME POINT TO ITSELF
if (this != &point_1)
{
this->x = point_1.x;
this->y = point_1.y;
this->z = point_1.z;
}
return *this;
}
} // nm_geometric
#endif // __CLASS_3D_POINT__