| 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
.
|
|
|
|
|

|
Related Articles |
|
|