Article View: comp.std.c++
Article #3424Re: Proposal: Reconcile Inheritance and Inlining
From: Dietmar Kuehl
Date: Fri, 23 Feb 1996 17:12
Date: Fri, 23 Feb 1996 17:12
65 lines
2517 bytes
2517 bytes
Hi,
Rich Hickey (hickeyr@ibm.net) wrote:
[Explanation of the proposal removed]
: class B{
: public:
: virtual int foo()const=0;
: //...
: };
: explicit class D:public B{
: public:
: int foo()const{return data;}
: //...
: private:
: int data;
: };
: void fred(const D &d)
: {
: d.foo(); //as if d.D::foo(); - inlined
: }
: void ethel(const B &b)
: {
: b.foo(); //even if b is a D, virtual function call (as always)
: }
: It cannot be otherwise accomplished in the language, i.e. it requires an extension.
I think it is easy to accomplish the thing you want to do in the language:
class E: public B {
public:
int foo_inline() const { return data; }
int foo() const { foo_inline(); }
private:
int data;
};
void foo(E const &e)
{
e.foo_inline(); // inline. Note that you know exactly the type of 'e'
e.foo(); // virtual as ever
}
Although I agree with you that your proposal is nicer to use, your
claim that it cannot be implemented in the language is wrong...
However, it would be nice to have a simple possibility to close a class
for further derivation (I know that it is possible using a friend and a
virutal base class but I think that this could even impose some runtime
penalty due to the representation of virtual bases).
--
dietmar.kuehl@uni-konstanz.de
http://www.informatik.uni-konstanz.de/~kuehl
I am a realistic optimist - that's why I appear to be slightly pessimistic
[ 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
]
Technical Details
Message-ID:
<4gkscd$8rl@news.BelWue.DE>Path:
arc1-ca.pugleaf.net!engnews1.Eng.Sun.COM!taumet!clamageReferences:
<4gkas9$4o84@news-s01.ny.us.ibm.net>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!engnews1.Eng.Sun.COM!taumet!clamage From: kuehl@uzwil.informatik.uni-konstanz.de (Dietmar Kuehl) Newsgroups: comp.std.c++ Subject: Re: Proposal: Reconcile Inheritance and Inlining Date: 23 Feb 1996 17:12:35 GMT Organization: Fakultät für Mathematik und Informatik Approved: clamage@eng.sun.com (comp.std.c++) Message-ID: <4gkscd$8rl@news.BelWue.DE> References: <4gkas9$4o84@news-s01.ny.us.ibm.net> Reply-To: dietmar.kuehl@uni-konstanz.de NNTP-Posting-Host: taumet.eng.sun.com Content-Type: text X-Nntp-Posting-Host: uzwil.informatik.uni-konstanz.de X-Newsreader: TIN [version 1.2 PL2] Content-Length: 1466 X-Lines: 58 Originator: clamage@taumet