🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #1840

Re: Equivalence of A and A<>

#1840
From: Pulkkinen Esa
Date: Thu, 24 Aug 1995 21:50
72 lines
2957 bytes
Distribution:
In article <199508241251.IAA03008@gold.interlog.com>,
Herb Sutter <herbs@interlog.com> wrote:
>gcato@st6000.sct.edu (Vaughn Cato) wrote:
>>I am curious as to the reasoning behind disallowing the use of a template
>>name as a synonym for a template id with no template parameters:
>>
>>template <class T = int> class A;
>>
>>void f()
>>{
>>  A<> *p1; // The legal way to default the argument
>>  A *p2;   // Syntax error
>>}
>
>If the latter was allowed, it would be ambiguous if a non-templated class A 
>existed.

Is it really so? 

[temp.names]/6 states:

"The name of a class template shall not be declared to refer
to any other template, class, function, object, enumeration, enumerator,
namespace, value or type in the same scope. ..."

That is, there can be no non-templated class A. And if it were allowed,
there would be a workaround for the problem, namely:
   typedef A<> A;

But as I understand it, this is not allowed. 

>Exactly, for similar reasons: it would be odd if your code suddenly broke 
>(became ambiguous and uncompilable) if someone added a variable that happened 
>to have the same name as a function you're using... without (), it wouldn't 
>be possible to differentiate the two.

I can't understand your point. You can't have a function and a variable
with the same name anyway. The reason for not allowing function calls
without () is (IMHO it's a shame) that you couldn't differentiate
between the function and its address (since function's name without ()
means its address). Consider:

typedef void (*FPTR)(void);
FPTR f();

void main()
{
  FPTR ptr = f; // call f and use return value to initialize ptr OR
                // initialize ptr with f (= type mismatch)
}

If I had the choice of re-designing the language, I would have disallowed
the bare function name to be used as a pointer to the function and
allowed the calls to functions without ().

But this problem doesn't apply to type names, and especially not
to class template parameters.

Or am I missing something?
-- 
   Esa Pulkkinen                        | C++ programmers do it virtually
   E-Mail:  esap@cs.tut.fi              | everywhere with a class, resulting
   WWW   :  http://www.cs.tut.fi/~esap/ | in multiple inheritance.




---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID: <MATT.95Aug24145052@physics2.Berkeley.EDU>
Path: arc1-ca.pugleaf.net!128.32.155.1!matt
References: <199508241251.IAA03008@gold.interlog.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!128.32.155.1!matt
From: esap@cs.tut.fi (Pulkkinen Esa)
Newsgroups: comp.std.c++
Subject: Re: Equivalence of A and A<>
Date: 24 Aug 1995 21:50:52 GMT
Organization: Tampere University of Technology
Approved: matt@physics2.Berkeley.EDU (Matt Austern)
Message-ID: <MATT.95Aug24145052@physics2.Berkeley.EDU>
References: <199508241251.IAA03008@gold.interlog.com>
NNTP-Posting-Host: physics2.berkeley.edu