Topic: [Q] Templates Functions within Template Classes?
Author: root@bnr.ca (0000-Admin(0000))
Date: 1995/07/31 Raw View
I'm trying to create a template function within a template class. Is there
any way to do this? I would have assumed it could be done as such:
template <class T>
class MyClass {
T var;
public:
MyClass(void);
template <class Parm1>
void Func(Parm1& P1)
{
/* do something P1-type independant */
}
};
MyClass<double> c1;
void test(int a, void* b)
{
c1.Func(a);
c1.Func(b);
}
but this will not compile (at least not with GCC 2.7). G++ gives the
following output:
560 - ~/tests> gcc template.cc -Wall
template.cc:8: parse error before `template'
template.cc:12: missing ';' before right brace
template.cc:13: parse error at end of class template
template.cc: In function `void test(int, void *)':
template.cc:21: `c1' undeclared (first use this function)
template.cc:21: (Each undeclared identifier is reported only once
template.cc:21: for each function it appears in.)
template.cc:21: `a' undeclared (first use this function)
template.cc:22: `b' undeclared (first use this function)
template.cc:20: warning: unused parameter `int a'
template.cc:20: warning: unused parameter `void * b'
Does anybody have any suggestions?
Brian
( bcwhite@bnr.ca )
-------------------------------------------------------------------------------
In theory, theory and practice are the same. In practice, they're not.