Simple question: Member function templates in template classes under VC++ 5.0 
Author Message
 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:
}



Fri, 17 Sep 1999 03:00:00 GMT  
 Simple question: Member function templates in template classes under VC++ 5.0



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

VC++ 5.0 officially does not support member templates, according to the
VC++ 5.0 readme.

Of course, they say that anything but the simplest member templates will
not work properly, leading me to believe that they DO support member
templates.  But I wouldn't bet on it.

Joe O'



Sat, 18 Sep 1999 03:00:00 GMT  
 Simple question: Member function templates in template classes under VC++ 5.0

Quote:
> VC++ 5.0 officially does not support member templates, according to the
> VC++ 5.0 readme.

> Of course, they say that anything but the simplest member templates will
> not work properly, leading me to believe that they DO support member
> templates.  But I wouldn't bet on it.

We have some code that uses member function templates, and it all appears
to work.  Of course, we wrote that before we saw the readme note that
says that we can't (or shouldn't depend on the results.)  

The code all seems to work, but I am a tad nervous about using code that
they tell me may not work properly - I have enough trouble with the thing
that are supposed to work....  We may pull it and rewrite to avoid the
situation.

My guess is that there are problems with the implementation, and if you
get into a situation were "strange" compiler messages or code behavior
appear, you may want to assume that you've found the fringes of this
support.

--
Kevin Clements
Manager, Internet Development
Software House Enterprise Solutions



Sun, 19 Sep 1999 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Using member function templates in template class under VC++ 5.0

2. template class with a template member function

3. Template member functions of template classes

4. calling template member function in template class

5. Function template as member in a class template

6. template member function - non template class - VC5 - error

7. calling template member function in template class

8. Member function templates in VC 5.0

9. template functions in template classes declared outside the class definition

10. Does VC++ 5.0 support member templates?

11. Does VC 5.0 support member templates?

12. Simple template bombs VC++ 5.0 with C1001

 

 
Powered by phpBB® Forum Software