bug-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Problem with template function


From: Mindy Desens
Subject: Problem with template function
Date: Thu, 02 Nov 2000 21:40:35 GMT

I have a problem with template functions nested withing a template class(I
forgot to cheack the more general case of template functions nested withing
a nontemplate class).  I'll give a simple example.

#include <iostream>

template <class A> struct O {
 template <class B> static void f1(B b) {cout << "in static function f1" <<
endl;};
 template <class B> static void f2() {cout << "in static function f2" <<
endl;};
 template <class B> void f3(B b) {cout << "in nonstatic function f3" <<
endl;};
 template <class B> void f4() {cout << "in nonstatic function f4" << endl;};
};

template <class A> void g1() {cout << "inside global function" << endl;};

main()
{

 O<int>::f1(33);
 g1<int>();     /* Works fine */
 O<int>::f2<int>(); /* Causes parse error */
 O<int> o;
 o.f3(33);
 o.f4<int>();       /* Causes parse error */
}

The problem is with template functions that cannot be determined from the
parameter list.  For some reason with the function g1() the compiler allows
me to explicitly specify the template parameters but with the functions f2()
and f4() explicit specification causes a parse error.  The compiler I'm
using is g++ - 2.91.66.  If anyone has a workaround for this problem please
let me know.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]