Topic: Problem with template overloading.
Author: wikman@research.nokia.com (Johan Wikman)
Date: 1996/02/22 Raw View
In article <4gdc6v$cqv@engnews1.Eng.Sun.COM> clamage@Eng.sun.com (Steve Clamage) writes:
Yes. Only in special cases would you not have insurmountable ambiguities.
Just as type names must be unique in one scope, so must template names.
I'd like to be able to have a class and a template with the same name
in the same scope.
Usually when I write a template, I derive it from a class that is only
used as a base class of the template.
class BaseX { ... };
template<class T> class X : public BaseX { ... };
Consequently I must invent a descriptive name for the base class and
usually I end up with Base-something or Abstract-something. I'd like
to be able to write:
class X { ... };
template<class T> class X : public X { ... };
I don't think there would be ambiguities as an X without a template
argument is the "class" X and an X with a template argument is
obviously the "template" X.
[ To submit articles: Try just posting with your newsreader.
If that fails, use mailto:std-c++@ncar.ucar.edu
FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html
Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]
Author: clamage@Eng.Sun.COM (Steve Clamage)
Date: 1996/02/22 Raw View
In article AA11584@garlic.spices, wikman@research.nokia.com (Johan Wikman)
writes:
>I'd like to be able to have a class and a template with the same name
>in the same scope.
class A { ... };
template <class T>
class A {
void foo() { .... A ... }
};
In A<T>::foo, I use the identifier "A". Does that refer to the template
or to the class? In order not to break all existing code, it must
refer to the template. In that case, how do I refer to the class?
Both things called "A" are in the same scope, and both can be used
where the name of a type is wanted.
Perhaps you can think of a special syntax that won't change the meaning
of existing code, or we could say that you can't refer to class A anywhere
in the scope of template A. The question is whether the extra complication
is justified. Remember, you can use longer "official" type or
template names, and add typedefs to make them easier to use.
---
Steve Clamage, stephen.clamage@eng.sun.com
---
[ To submit articles: try just posting with your news-reader.
If that fails, use mailto:std-c++@ncar.ucar.edu
FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html
Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu.
]
Author: fjh@munta.cs.mu.OZ.AU (Fergus Henderson)
Date: 1996/02/22 Raw View
clamage@Eng.Sun.COM (Steve Clamage) writes:
>Remember, you can use longer "official" type or
>template names, and add typedefs to make them easier to use.
You would be able to do so, if C++ supported template typedefs...
but it doesn't.
--
Fergus Henderson WWW: http://www.cs.mu.oz.au/~fjh
fjh@cs.mu.oz.au PGP: finger fjh@128.250.37.3
---
[ To submit articles: Try just posting with your newsreader. If that fails,
use mailto:std-c++@ncar.ucar.edu
FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html
Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]
Author: wikman@research.nokia.com (Johan Wikman)
Date: 1996/02/23 Raw View
In article <4gi7h0$l0@engnews1.Eng.Sun.COM> clamage@Eng.Sun.COM (Steve Clamage) writes:
> In article AA11584@garlic.spices, wikman@research.nokia.com (Johan Wikman)
> writes:
>
> >I'd like to be able to have a class and a template with the same name
> >in the same scope.
>
> class A { ... };
>
> template <class T>
> class A {
> void foo() { .... A ... }
> };
>
> In A<T>::foo, I use the identifier "A". Does that refer to the template
> or to the class? In order not to break all existing code, it must
> refer to the template.
Interesting, I always thought you had to use A<T>. Now that I tried
it, all compilers I have access to (HP, gcc and MS VC++) accepted both
A and A<T>. What does the standard say? Are both versions allowed?
> Perhaps you can think of a special syntax that won't change the meaning
> of existing code, or we could say that you can't refer to class A anywhere
> in the scope of template A.
No, I won't even try. But I definitely find using A<T> within the
definition of a template's function more intuitive than just using
A. Making A<T> a requirement certainly wouldn't break my code;-).
--
johan.wikman@research.nokia.com
[ To submit articles: Try just posting with your newsreader.
If that fails, use mailto:std-c++@ncar.ucar.edu
FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html
Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]