Thread overview
RE: Odd Template Error
Feb 26, 2004
resistor
Re: Odd Template Error
Feb 26, 2004
Ben Hinkle
[bug] Re: Odd Template Error
Feb 26, 2004
resistor
Feb 26, 2004
Sark7
February 26, 2004
OK, I isolated that templating error down.  I have a class Tree!(T).  Every
Tree!(T) needs to have two
member variables that are also Tree!(T)'s.  However, if I just declare them like
such:

Tree!(T) left;
Tree!(T) right;

I get an error.  What is the proper way to declare them?

Owen


February 26, 2004
<resistor@mac.com> wrote in message news:c1jf0l$rla$1@digitaldaemon.com...
| OK, I isolated that templating error down.  I have a class Tree!(T).  Every
| Tree!(T) needs to have two
| member variables that are also Tree!(T)'s.  However, if I just declare them
like
| such:
|
| Tree!(T) left;
| Tree!(T) right;
|
| I get an error.  What is the proper way to declare them?
|
| Owen

I think that is a compiler bug in the undocumented class-template syntax. The solution is to write

  class Tree(T)
  {
    Tree left;
    Tree right;
    ...
  }

[note you leave out the !(T) in the class body] or

  template Tree(T)
  {
    class Tree
    {
      Tree left;
      Tree right;
      ...
    }
  }

Sometimes I've wondered about using this! to refer to the template currently being defined, but that seems a little too wierd to use unless there is a good reason why other syntax choices fail.

-Ben


February 26, 2004
Walter,

Would there be any chance of getting this fixed?  If a templated class can
create instances other
templated classes as Class!(T), should it also be able create instances of
itself with the same syntax?

Owen

In article <c1jgav$tv7$1@digitaldaemon.com>, Ben Hinkle says...
>
><resistor@mac.com> wrote in message news:c1jf0l$rla$1@digitaldaemon.com...
>| OK, I isolated that templating error down.  I have a class Tree!(T).  Every
>| Tree!(T) needs to have two
>| member variables that are also Tree!(T)'s.  However, if I just declare them
>like
>| such:
>|
>| Tree!(T) left;
>| Tree!(T) right;
>|
>| I get an error.  What is the proper way to declare them?
>|
>| Owen
>
>I think that is a compiler bug in the undocumented class-template syntax. The solution is to write
>
>  class Tree(T)
>  {
>    Tree left;
>    Tree right;
>    ...
>  }
>
>[note you leave out the !(T) in the class body] or
>
>  template Tree(T)
>  {
>    class Tree
>    {
>      Tree left;
>      Tree right;
>      ...
>    }
>  }
>
>Sometimes I've wondered about using this! to refer to the template currently being defined, but that seems a little too wierd to use unless there is a good reason why other syntax choices fail.
>
>-Ben
>
>


February 26, 2004
On Thu, 26 Feb 2004 00:35:34 +0000 (UTC), <resistor@mac.com> wrote:

> OK, I isolated that templating error down.  I have a class Tree!(T).  Every
> Tree!(T) needs to have two
> member variables that are also Tree!(T)'s.  However, if I just declare them like
> such:
>
> Tree!(T) left;
> Tree!(T) right;
>
> I get an error.  What is the proper way to declare them?
>
> Owen
>
>

Try
  .Tree!(T) left;
  .Tree!(T) right;

--
Sark7