Pure virtual function of template class (undefined reference)

ishape.h
1
2
3
4
5
6
7
8
9
10
11
template < typename T >
class IShape {

public:

    IShape() {}

    virtual void move(const T&, const T& = 0, const T& = 0) = 0;

    virtual ~IShape() {}
};


ishape_2d.h
1
2
3
4
5
6
7
8
9
10
11
12
#include "ishape.h"

template <typename T>
class IShape_2D : public IShape< T> {
public:

    IShape_2D() {}

    virtual T perimeter() const = 0;

    virtual ~IShape_2D() {}
};


polygon.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#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.


any ideas?
closed account (o1vk4iN6)
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.
Topic archived. No new replies allowed.