Article View: comp.std.c++
Article #3437Re: Proposal: Reconcile Inheritance and Inlining
From: Alexandre Oliva
Date: Sun, 25 Feb 1996 00:06
Date: Sun, 25 Feb 1996 00:06
69 lines
2844 bytes
2844 bytes
Rich Hickey writes:
> Proposal: Reconcile Inheritance and Inlining
> --------------------------------------------
> Rich Hickey
> rich@rcs-hq.mhs.compuserve.com
> -----------------------------------------------------------------------
> I propose that the explicit keyword be allowed as a qualifier of a class
> definition, such qualification taking the form of:
> explicit class X{
> //the definition of X
> };
> and that such qualification has the following meaning:
> For any class X defined as explicit -
> X cannot be derived from.
> Any calls to member functions of X, even through pointers or references
> to X, be called with the 'normal' function mechanism, i.e. not the
> virtual function mechanism, as if the call took the form of
> x-> X::function(). That is to say, all calls on X's are in the explicit
> scope of X. (Language lawyers please refine)
The 'normal' function mechanism can be used for any method not
declared as virtual. The only exception I can think of is when a base
class declares a virtual function you do not want to reimplement, but
you also do not want to pay for the cost of virtual invocations:
class Base {
public:
virtual void foo();
};
inline void Base::foo() {}
class Derived : public Base {};
main() {
Derived X;
X.foo();
}
You can allow foo's code to be inlined by changing the declaration of
Derived to:
class Derived : public Base {
public:
inline void foo() { Base::foo(); }
};
Since Derived::foo is not virtual, in can be inlined, as well as
Base::foo could, since it is given a scope specifier. Although this
requires some more lines of code, no changes in the standard are
required.
--
Alexandre Oliva
oliva@dcc.unicamp.br
Universidade Estadual de Campinas, S~ao Paulo, Brasil
[ 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:
<or4tsgfvgl.fsf@grande.dcc.unicamp.br>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: oliva@grande.dcc.unicamp.br (Alexandre Oliva) Newsgroups: comp.std.c++ Subject: Re: Proposal: Reconcile Inheritance and Inlining Date: 25 Feb 1996 00:06:05 GMT Organization: DCC - UNICAMP - Campinas, SP, Brazil Sender: oliva@grande.dcc.unicamp.br Approved: clamage@eng.sun.com (comp.std.c++) Message-ID: <or4tsgfvgl.fsf@grande.dcc.unicamp.br> References: <4gkas9$4o84@news-s01.ny.us.ibm.net> NNTP-Posting-Host: taumet.eng.sun.com Content-Type: text X-Nntp-Posting-Host: grande.dcc.unicamp.br In-Reply-To: hickeyr@ibm.net's message of 23 Feb 1996 15:55:20 GMT X-Newsreader: Gnus v5.1 Content-Length: 1761 Originator: clamage@taumet