Topic: Rationale behind "class" in a template declaration?


Author: "Carl Daniel" <cpdaniel@pacbell.net>
Date: Thu, 7 Feb 2002 21:06:20 GMT
Raw View
"disgruntled goat" <the_disgruntled_goat@hotmail.com> wrote in message
news:818a6a96.0202062308.407f410b@posting.google.com...
> Why is the keyword 'class' used here?
>
> template<class T> void func(T);
>          ^^^^^

Two words:  Backwards compatibility.

This usage was common long before the 'typename' keyword was added to the
language.
-cd

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]





Author: Ron Natalie <ron@sensor.com>
Date: Fri, 8 Feb 2002 01:11:07 GMT
Raw View

disgruntled goat wrote:
>
> Why is the keyword 'class' used here?
>
> template<class T> void func(T);
>          ^^^^^
>
> Why did the standards committee not just state that 'typename' must be
> used?

Because C++ was using class for that purpose long before anybody came up with
the typename keyword.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]





Author: comeau@panix.com (Greg Comeau)
Date: Fri, 8 Feb 2002 01:11:21 GMT
Raw View
In article <818a6a96.0202062308.407f410b@posting.google.com>,
disgruntled goat <the_disgruntled_goat@hotmail.com> wrote:
>Why is the keyword 'class' used here?
>
>template<class T> void func(T);
>         ^^^^^
>
>Why did the standards committee not just state that 'typename' must be
>used?  Is there a good reason to allow 'class' in a template
>declaration when one can already use typename?  It in no way mandates
>the parameters be of class type, and is thus causes a needless bit of
>confusion.
>
>Basically I'm just confused.  The keyword 'typename' would seem to be
>perfect for this situation.  Why allow 'class' as well?  The only
>possible reason I can think of is if 'typename' was not added to the
>standard until *after* templates had been originated.

And that's what happened (it was added to the draft a bit after
templates were in implementations already).

Some people actually like class there (personally I don't) too.
--
Greg Comeau  GA BETA:4+ New Windows Backends  PLUS 'export' beta online!
Comeau C/C++ ONLINE ==>     http://www.comeaucomputing.com/tryitout
World Class Compilers:  Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]





Author: the_disgruntled_goat@hotmail.com (disgruntled goat)
Date: Thu, 7 Feb 2002 18:21:05 GMT
Raw View
Why is the keyword 'class' used here?

template<class T> void func(T);
         ^^^^^

Why did the standards committee not just state that 'typename' must be
used?  Is there a good reason to allow 'class' in a template
declaration when one can already use typename?  It in no way mandates
the parameters be of class type, and is thus causes a needless bit of
confusion.

Basically I'm just confused.  The keyword 'typename' would seem to be
perfect for this situation.  Why allow 'class' as well?  The only
possible reason I can think of is if 'typename' was not added to the
standard until *after* templates had been originated.

If anyone can straighten this out for me, please do.  Thanks.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]