Article View: comp.std.c++
Article #680Re: The concept of templates considered ill designed
From: Andrew Koenig
Date: Wed, 07 Oct 1992 12:52
Date: Wed, 07 Oct 1992 12:52
43 lines
1691 bytes
1691 bytes
In article <IeoW7Ca00awVEGbFIn@andrew.cmu.edu> osoelgaultier+@CMU.EDU (Stefan Monnier) writes:
> What's the problem ?
> Why not take option 2 ?
> Every Baz object has method Foo::mem(int) cause it has inherited it
> from Foo.
> If you don't agree with it, why use inheritance ?
Well, let's make it more explicit.
class Foo {
public:
void mem(int);
};
class Bar: public Foo {
public:
void mem(int);
};
template<class T> void f(T x) { x.mem(); }
main()
{
Bar b;
f(b);
}
The whole point of templates is that the call f(b) should result in
calling Bar::mem, because b is an object of type Bar.
What you're saying is that you want f(b) to call Foo::mem if the template
function f has a constraint that T is Foo or derived from Foo.
It's already easy to obtain such behavior -- just don't bother with
templates at all!
In other words, I don't think option 2 is viable. Do you still think
so after seeing this example?
--
--Andrew Koenig
ark@europa.att.com
Technical Details
Message-ID:
<23829@alice.att.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!portal!lll-winken!sol.ctr.columbia.edu!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!att!allegra!alice!arkReferences:
<RAYMOND.92Sep29122502@cobra.es.ele.tue.nl> <0enxJ1W00awTMNepU8@andrew.cmu.edu> <23808@alice.att.com> <Yeo91je00awVE_zEkI@andrew.cmu.edu> <23822@alice.att.com> <IeoW7Ca00awVEGbFIn@andrew.cmu.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!portal!lll-winken!sol.ctr.columbia.edu!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!att!allegra!alice!ark From: ark@alice.att.com (Andrew Koenig) Newsgroups: comp.std.c++,comp.lang.c++ Subject: Re: The concept of templates considered ill designed Message-ID: <23829@alice.att.com> Date: 7 Oct 92 12:52:17 GMT References: <RAYMOND.92Sep29122502@cobra.es.ele.tue.nl> <0enxJ1W00awTMNepU8@andrew.cmu.edu> <23808@alice.att.com> <Yeo91je00awVE_zEkI@andrew.cmu.edu> <23822@alice.att.com> <IeoW7Ca00awVEGbFIn@andrew.cmu.edu> Reply-To: ark@alice.UUCP () Organization: AT&T Bell Laboratories, Murray Hill NJ Lines: 43