Topic: The more I use them, the more I hate templates...


Author: dyes@convex.com (Tim Dyes)
Date: 1995/07/11
Raw View
Mike McCarty (mikem@yosemite.eai.com) wrote:

: If this is not an allowable construct, I really fail to see the point of
: using templates at all...

yes, sometimes the language forces you to order things properly for the
compiler.  Forget using inline function defs for which the size of the
things being dealt with is not yet known.  For your example I get a clean
compile on hpux with it rewritting as:

template<class T>class Aay;  // forward declaration

class Bee
{
public:
  int  t;

  void  foo(Aay<Bee>& f);   // reference so size not needed at this point
};

template <class T>
class Aay
{
public:
  T i;                      // Bee size is now known
};

void main(int, char **)
{ }

void Bee::foo(Aay<Bee>& f)
{  f = f; }







Author: mikem@yosemite.eai.com (Mike McCarty)
Date: 1995/07/08
Raw View
Compiling the following simple program on an HP workstation running HP-UX
9.07, I get the following errors:

% CC testtmpl.C
CC: "testtmpl.C", line 7: error:  Bee undefined, size not known (1437)
"testtmpl.C", line 7:    error detected during the instantiation ofAay <Bee>
"testtmpl.C", line 15:   is the site of the instantiation


-----  BEGIN PROGRAM ------


template <class T>
class Aay
{
public:
  T i;
};

class Bee
{
public:
  int  t;

  inline void  foo(Aay<Bee>& f)    {  f = f; }
};

void main(int, char **)
{ }

------  END PROGRAM  ------


Please tell me this is a problem with HP's C++ compiler...  I get similar
errors using gcc 2.7.0 but not with SGI's Delta C++ compiler which has a
looser interpretation of the language.  Knowing that SGI's compiler
can deal with it properly (i.e. the problem is resolvable) and thinking
that there is nothing inherently illegal about this structure to begin
with, why are these compilers choking on this???

If this is not an allowable construct, I really fail to see the point of
using templates at all...

I used to think templates were cool (back when I didn't know anything about
them).  Now, considering the lack of nested templates and
preprocessor-style template conditionals, I really wish I'd never heard of the
goddamn things...

--
--------------------------------+-----------------------------------------------
Michael McCarty  (mikem@eai.com)| What would happen in a battle between an
Engineering Animation Inc. | Enterprise security team who always get killed
Ames, IA  50010   | soon after appearing, and a squad of Imperial
Work: (515) 296-9908  | Stormtroopers, who can't hit the broad side of
Home: (None of your business) | of a planet?      -- Tom Galloway





Author: John Reah <reahj2@btlip12.bt.co.uk>
Date: 1995/07/10
Raw View
Try a forward declaration of Aay like this:
-------------------------------------------

template <class T> class Aay;

class Bee
{
public:
  int  t;

  inline void  foo(Aay<Bee>& f)    {  f = f; }
};

template <class T>
class Aay
{
public:
  T i;
};

void main(int, char **)
{ }