I'm writing a program to test concrete inheritance, though I cannot resolve the duplicate symbol linker error Clang returns. My understanding is duplicate symbols is always the result of incorrect includes/guards. I have triple checked my includes/guards, but I cannot find any errors. Could the duplicate symbol be the result of something other than include guards? Many thanks, as I grow my programming skills I intend to contribute here frequently.
.h
#ifndef POINTARRAY_H
#define POINTARRAY_H
#include "array.h"
namespace Jules
{
namespace Containers
{
class PointArray: public Array<Point>
{
public:
PointArray(); //default constructor
~PointArray(); //destructor
PointArray(const PointArray& p); //copy constructor
PointArray(const int i); //constructor with input argument
PointArray& operator = (const PointArray& source); //assignment operator
double Length() const; //length between points in array
};
}
}
#ifndef POINTARRAY_CPP
#include "PointArray.cpp"
#endif
#endif
.cpp
#ifndef POINTARRAY_CPP
#define POINTARRAY_CPP
#include "PointArray.h"
using namespace Jules::CAD;
namespace Jules
{
namespace Containers
{
PointArray::PointArray() : Array<Point>() //default constructor
{
}
PointArray::~PointArray() //destructor
{
}
PointArray::PointArray(const PointArray& p) : Array<Point>(p) //copy constructor
{
}
PointArray::PointArray(const int i) : Array<Point>(i) //constructor with input argument
{
}
PointArray& PointArray::operator = (const PointArray& source) //assignment operator
{
if (this == &source)
return *this;
PointArray::operator = (source);
return *this;
}
double PointArray::Length() const
{
double lengthOfPoints = 0;
for (int i = 0; i < Array::Size()-1; i++)
lengthOfPoints += (*this)[i].Distance((*this)[i+1]);
return lengthOfPoints;
}
}
}
#endif
Update: Thank you everyone for your help. I understand the mechanics now.