Topic: Member templates
Author: Srinivas Vobilisetti <srinivas@tcsi.com>
Date: 1996/04/20 Raw View
Though this is not supported before, the DWP supports it. Obvious it behaves
like a normal template function and will be instantiated only when it is first
invoked. Also template function f(int) will override and f(T) when T != int
will hide the base class f(int). I don't remember the exact DWP section
numbers. I am not sure whether it will exhibit run-time binding.
Srinivas Vobilisetti
[ 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 ]
[ 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: Roman Lechtchinsky <wolfro@cs.tu-berlin.de>
Date: 1996/04/20 Raw View
David Vandevoorde wrote:
>
> >>>>> "RL" == Roman Lechtchinsky <wolfro@cs.tu-berlin.de> writes:
> [...]
> RL> class Base
> RL> {
> RL> virtual void f(int);
> RL> };
>
> RL> class Derived : Base
> RL> {
> RL> template<class T> void f(T);
> RL> };
>
> RL> Is this legal? If so, will the template function f(int) override
> RL> Base::f(int)? If so, when will it be instantiated? And, last but not
> RL> least, which section of the DWP handles this case? Thanks in advance.
>
> I believe this is legal and the instantiated member function is not
> virtual (i.e., no overriding), but my reason extrapolates the WPs
> somewhat. I base this on the fact that the `signature' of a template
> function includes the actual template arguments ([temp.over.link]
> 14.10.4/3 in the April CD), and that when [class.virtual] 10.3/2
> requires `same name', `name' really means template-id and not just
> template-name ([temp.names] 14.1).
>
IMO, this means that f cannot be overridden in Derived:
class Derived : Base
{
template<class T> void f(T);
void f(int);
};
would be a specialization which means that f doesn't override as it is still
a template ( [temp.over.spec] 14.10.5 ). Is this interpretation correct?
Bye
Roman
---
[ 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 ]
[ 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: vandevod@cs.rpi.edu (David Vandevoorde)
Date: 1996/04/21 Raw View
>>>>> "RL" == Roman Lechtchinsky <wolfro@cs.tu-berlin.de> writes:
RL> David Vandevoorde wrote:
>>
>> >>>>> "RL" == Roman Lechtchinsky <wolfro@cs.tu-berlin.de> writes:
>> [...]
RL> class Base
RL> {
RL> virtual void f(int);
RL> };
>>
RL> class Derived : Base
RL> {
RL> template<class T> void f(T);
RL> };
>>
RL> Is this legal? If so, will the template function f(int) override
RL> Base::f(int)? If so, when will it be instantiated? And, last but not
RL> least, which section of the DWP handles this case? Thanks in advance.
>>
>> I believe this is legal and the instantiated member function is not
>> virtual (i.e., no overriding), but my reason extrapolates the WPs
>> somewhat. I base this on the fact that the `signature' of a template
>> function includes the actual template arguments ([temp.over.link]
>> 14.10.4/3 in the April CD), and that when [class.virtual] 10.3/2
>> requires `same name', `name' really means template-id and not just
>> template-name ([temp.names] 14.1).
>>
RL> IMO, this means that f cannot be overridden in Derived:
RL> class Derived : Base
RL> {
RL> template<class T> void f(T);
RL> void f(int);
RL> };
RL> would be a specialization which means that f doesn't override as it is
^^^^^^^^^^^^^^
To me more precise: it would be a ``guiding member-function declaration'',
if such a beast is supposed to exist (i.e., it declares a specialization,
but only to guide overloading resolution --- the definition is still
generated from the template). However...
RL> still a template ( [temp.over.spec] 14.10.5 ). Is this interpretation
RL> correct?
Frankly, I don't know. I can see three reasonable possibilities:
1) your interpretation,
2) it is not a guiding declaration but an overriding function.
A guiding declaration could instead perhaps be declared via:
struct Derived: Base {
template<typename T>
void f(T);
void f<int>(int); // Guiding member function declaration
void f(int); // Virtual function overriding Base::f(int);
};
3) it is simply illegal C++ code.
I suspect 1) is true, but I'm really not sure at all...
Daveed
---
[ 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 ]
[ 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: Roman Lechtchinsky <wolfro@cs.tu-berlin.de>
Date: 1996/04/22 Raw View
David Vandevoorde wrote:
>
> >>>>> "RL" == Roman Lechtchinsky <wolfro@cs.tu-berlin.de> writes:
> RL> David Vandevoorde wrote:
> >>
> >> >>>>> "RL" == Roman Lechtchinsky <wolfro@cs.tu-berlin.de> writes:
> >> [...]
> RL> class Base
> RL> {
> RL> virtual void f(int);
> RL> };
> >>
> RL> class Derived : Base
> RL> {
> RL> template<class T> void f(T);
> RL> };
> >>
> RL> Is this legal? If so, will the template function f(int) override
> RL> Base::f(int)? If so, when will it be instantiated? And, last but not
> RL> least, which section of the DWP handles this case? Thanks in advance.
> >>
> >> I believe this is legal and the instantiated member function is not
> >> virtual (i.e., no overriding), but my reason extrapolates the WPs
> >> somewhat. I base this on the fact that the `signature' of a template
> >> function includes the actual template arguments ([temp.over.link]
> >> 14.10.4/3 in the April CD), and that when [class.virtual] 10.3/2
> >> requires `same name', `name' really means template-id and not just
> >> template-name ([temp.names] 14.1).
> >>
>
> RL> IMO, this means that f cannot be overridden in Derived:
>
> RL> class Derived : Base
> RL> {
> RL> template<class T> void f(T);
> RL> void f(int);
> RL> };
>
> RL> would be a specialization which means that f doesn't override as it is
> ^^^^^^^^^^^^^^
> To me more precise: it would be a ``guiding member-function declaration'',
> if such a beast is supposed to exist (i.e., it declares a specialization,
> but only to guide overloading resolution --- the definition is still
> generated from the template). However...
To be even more precise, it is "a specialization but not an explicit
specialization" [temp.over.spec] ;-)
> RL> still a template ( [temp.over.spec] 14.10.5 ). Is this interpretation
> RL> correct?
>
> Frankly, I don't know. I can see three reasonable possibilities:
>
> 1) your interpretation,
> 2) it is not a guiding declaration but an overriding function.
> A guiding declaration could instead perhaps be declared via:
>
> struct Derived: Base {
> template<typename T>
> void f(T);
> void f<int>(int); // Guiding member function declaration
> void f(int); // Virtual function overriding Base::f(int);
> };
>
> 3) it is simply illegal C++ code.
>
> I suspect 1) is true, but I'm really not sure at all...
Neither 1) nor 2) seem acceptable to me. 3) is good option but there is a
better way, I think. Why not say:
A template member function overrides a virtual function if and only if it is
declared virtual.
With this rule, f wouldn't override in my example. To make it virtual one
would have to declare:
class Derived : Base
{
template<class T> void f(T);
virtual void f(int);
};
Here, f(int) would either override an existing virtual function ( as it
happens in this case ) or define a new virtual function. I'm not sure if the
definition should be created from the template. My personal opinion is that
the above should be a virtual guiding member-function declaration and that
the following should be legal, too:
class Derived : Base
{
template<class T> void f(T);
template<> virtual void f(int);
};
Here we have an virtual explicit specialization. Do you think this is too
complicated?
Bye
Roman
---
[ 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 ]
[ 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: boukanov@hadron.fi.uib.no (Igor Boukanov)
Date: 1996/04/22 Raw View
Here another question about member templates:
Does the following code declare copy constructor for class A?
class A {
public:
template<class B> A(const B&);
};
--
Regards, Igor Boukanov.
igor.boukanov@fi.uib.no
http://www.fi.uib.no/~boukanov/
[ 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 ]
[ 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: Roman Lechtchinsky <wolfro@cs.tu-berlin.de>
Date: 1996/04/19 Raw View
Hi,
the question is about member templates and virtual functions. I know these
are prohibited. However, what about the following example:
class Base
{
virtual void f(int);
};
class Derived : Base
{
template<class T> void f(T);
};
Is this legal? If so, will the template function f(int) override
Base::f(int)? If so, when will it be instantiated? And, last but not least,
which section of the DWP handles this case? Thanks in advance.
Bye
Roman
---
[ 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 ]
[ 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: vandevod@cs.rpi.edu (David Vandevoorde)
Date: 1996/04/19 Raw View
>>>>> "RL" == Roman Lechtchinsky <wolfro@cs.tu-berlin.de> writes:
[...]
RL> class Base
RL> {
RL> virtual void f(int);
RL> };
RL> class Derived : Base
RL> {
RL> template<class T> void f(T);
RL> };
RL> Is this legal? If so, will the template function f(int) override
RL> Base::f(int)? If so, when will it be instantiated? And, last but not
RL> least, which section of the DWP handles this case? Thanks in advance.
I believe this is legal and the instantiated member function is not
virtual (i.e., no overriding), but my reason extrapolates the WPs
somewhat. I base this on the fact that the `signature' of a template
function includes the actual template arguments ([temp.over.link]
14.10.4/3 in the April CD), and that when [class.virtual] 10.3/2
requires `same name', `name' really means template-id and not just
template-name ([temp.names] 14.1).
Daveed
---
[ comp.std.c++ is moderated. To submit articles: Try just posting with your
newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]