Thread View: comp.std.c++
3 messages
3 total messages
Started by Johan Wikman
Thu, 22 Feb 1996 15:51
Re: Problem with template overloading.
Author: Johan Wikman
Date: Thu, 22 Feb 1996 15:51
Date: Thu, 22 Feb 1996 15:51
32 lines
1809 bytes
1809 bytes
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
]
Re: Problem with template overloading.
Author: Steve Clamage
Date: Thu, 22 Feb 1996 17:12
Date: Thu, 22 Feb 1996 17:12
33 lines
1894 bytes
1894 bytes
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.
]
Re: Problem with template overloading.
Author: Fergus Henderson
Date: Thu, 22 Feb 1996 17:42
Date: Thu, 22 Feb 1996 17:42
18 lines
1420 bytes
1420 bytes
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
]
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads