template memberfunctions

U

Uwe Mayer

Hi,

I'm trying to create a template memberfunction in a non-template class,
using gcc under Linux:

plot.h:

namespace ml {
class Axes {
public:
Axes(double id);
~Axes();

template <typename T> LinePlot& plot(T *x, T *y, char *options=0);
};
}

A function definition (outside the namespace ml, but still inside the header
file works, i.e.

template <typename T> ml::LinePlot& ml::Axes::plot(T *x, T *y, char
*options) {
fprintf(stderr, "test\n");
}

If I move the same definition from the .h to the .cpp file I get a linking
error:

undefined reference to `ml::LinePlot&
ml::Axes::plot<gsl_vector>(gsl_vector*, gsl_vector*, char*)'

Any ideas whats going on here?

Thanks in advance
Ciao
Uwe
 
V

Victor Bazarov

Uwe said:
Hi,

I'm trying to create a template memberfunction in a non-template
class, using gcc under Linux:

plot.h:

namespace ml {
class Axes {
public:
Axes(double id);
~Axes();

template <typename T> LinePlot& plot(T *x, T *y, char *options=0);
};
}

A function definition (outside the namespace ml, but still inside the
header file works, i.e.

template <typename T> ml::LinePlot& ml::Axes::plot(T *x, T *y, char
*options) {
fprintf(stderr, "test\n");
}

If I move the same definition from the .h to the .cpp file I get a
linking error:

undefined reference to `ml::LinePlot&
ml::Axes::plot<gsl_vector>(gsl_vector*, gsl_vector*, char*)'

Any ideas whats going on here?

FAQ 35.15

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,586
Members
45,097
Latest member
RayE496148

Latest Threads

Top