
Simple question: Member function templates in template classes under VC++ 5.0
Hi!
I have a rather simple question about the C++ language as implemented by
VC++ 5.0. The question itself is a straightforward one, but it does
involve a new feature of the language present starting only in VC++ 5.0:
Member Function Templates.
In particular, I'm trying to find a way to use member function templates
within template classes under VC++ 5.0 As the code below illustrates,
when I define the body of a member function template "inline" (that is,
within the template class definition itself), things seem to work fine.
But I get in hot water when I try to defer the definition of a member
function template until after the surrounding class has been defined. In
other words, in the code below, I can't figure out *any* way to define
"SimpleFn" outside the "Container" class (or even to define
specializations of it for particular instances, which is not what is
needed, but somewhat related to it,)
Any help would be **enormously** appreciated -- will be glad to put in a
note of thanks into the doct{*filter*}dissertation you helped facilitate!
Nate Osgood
#include <stdio.h>
// #define INLINE_DEFINITION 1 // uncomment the beginning of the line to
allow the inline version of the member function template to be used without
problems
template<class T> class Container
{
int w;
public:
Container(int t) : w(t) { }
#ifdef INLINE_DEFINITION
template<class S> void SimpleFn(S *p)
{
printf("In call to inline `SimpleFn'\n");
}
#else
// here's the *declaration* -- the question is how to define this outside
this class
template<class S> void SimpleFn(S *p);
#endif
Quote:
};
// ??? how to define SimpleFn out here? ???
Container<int> c(100);
int main()
{
c.SimpleFn((long *) 0);
return(0);
Quote:
}