Topic: TEMPLATE problem


Author: jamshid@ses.com (Jamshid Afshar)
Date: Tue, 19 Apr 1994 23:44:11 GMT
Raw View
In article <2ogufs$b47@leps5.phys.psu.edu>,
James M Dailey <jgalt@leps5.phys.psu.edu> wrote:
>typedef int Bool;
>
>template <class Type> class Snafu {
>protected:
>  static Bool (*compare_s)(const Type&, const Type&);
>};
>
>   template<class Type>
>   Bool (*Snafu<Type>::compare_s)(const Type&, const Type&) = &Some_function;
>
>and I keep getting the error
>
> File <Snafu.cpp>; Line 9 [at the compare_s definition]
> Error:   'Bool' is not a class template
>
>I have previouisly defined Bool to be of type int, but when I change Bool to
>an built-in class type, all is well.  Is there something wrong with thesyntax
>for the data member initialization, or is it mycompiler (Symmantec C++ 7.0)?

There's nothing wrong with your syntax.  Ask your compiler company
(Symantec) why they can't get this code right even though I've sent
them (and Zortech) a copy of my JCOOL library (which widely uses the
above construct), encouraging them to use JCOOL as a test of their
template implementation.  Edison Design Group, Borland and Watcom have
all done so, and it shows in their high quality template
implementations.  There's just no excuse for such buggy compilers (the
latest Cfront and g++ also cannot handle JCOOL) when test cases are so
easily available at ftp sites (see the Class Libraries FAQ).  I wish
our QA department had it so easy.

Jamshid Afshar
jamshid@ses.com




Author: jgalt@leps5.phys.psu.edu (James M Dailey)
Date: 13 Apr 1994 10:10:04 -0400
Raw View
I'm trying to initialize the  static data member "compare_s" (which happens
to be a pointer to a function) in class "Snafu", with the following line in
the definition file Snafu.cpp:

   template<class Type>
   Bool (*Snafu<Type>::compare_s)(const Type&, const Type&) = &Some_function;

and I keep getting the error

 File <Snafu.cpp>; Line 9
 Error:   'Bool' is not a class template


In snafu.h we have:
-----------------
typedef int Bool;

template <class Type> class Snafu {
protected:

  Type* data;     // Pointer to allocated storage
  static Bool (*compare_s)(const Type&, const Type&); // Pointer operator== function
};

#include "snafu.cpp"


AND In snafu.cpp we have:
-----------------------
// compare_s -- static data member of Snafu, pointer to Type operator==

template<class Type>
Bool (*Coolpooh<Type>::compare_s)(const Type&, const Type&) = &Some_function;



I have previouisly defined Bool to be of type int, but when I change Bool to
an built-in class type, all is well.  Is there something wrong with the syntax
for the data member initialization, or is it my compiler (Symmantec C++ 7.0)?
Thanx for your help.

-james