template memberfunctions



 DEVELOP > c-Plus-Plus > template memberfunctions

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: "Uwe Mayer"
Date: 01 Aug 2007 07:48:16 AM
Object: template memberfunctions
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
.

User: "Victor Bazarov"

Title: Re: template memberfunctions 01 Aug 2007 09:02:55 AM
Uwe Mayer wrote:

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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
.
User: "Uwe Mayer"

Title: Re: template memberfunctions 01 Aug 2007 09:49:55 AM
Victor Bazarov wrote:


FAQ 35.15

V

Thanks!
Ciao
Uwe
.



  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER