#include "ishape_2d.h"
template< typename T>
class Polygon : public IShape_2D< T>
{
public:
Polygon() {}
~Polygon() {}
void move(const T&, const T&, const T&);
}
template< typename T>
void Polygon< T >::move(const T& x, const T& y, const T& z)
{
}
template< typename T >
T Polygon< T >::perimeter() const
{
return 0;
}
main.cpp
1 2 3 4 5 6 7 8 9
#include "polygon.h"
int main()
{
Polygon<float> pentagon;
return 0;
}
An error keeps coming
debug/main.o:main.cpp:(.rdata$_ZTVN3geo9IShape_2DIfEE[vtable for IShape_2D<float>]+0xc): undefined reference to `IShape<float>::move(float const&, float const&, float const&)'
debug/main.o:main.cpp:(.rdata$_ZTVN3geo6IShapeIfEE[vtable for IShape<float>]+0xc): undefined reference to `IShape<float>::move(float const&, float const&, float const&)'
collect2: ld returned 1 exit status
The process "C:\mingw\bin\mingw32-make.exe" exited with code 2.
Is it defined in the header file ? Since it's a template class the implementation needs to be visible in the header file, it can't be in the source as it has to be compiled dependent on the type.