Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Subtyping
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===C++=== The following C++ code establishes an explicit inheritance relationship between classes '''B''' and '''A''', where '''B''' is both a subclass and a subtype of '''A''', and can be used as an '''A''' wherever a '''B''' is specified (via a reference, a pointer or the object itself). <syntaxhighlight lang=cpp>class A { public: void DoSomethingALike() const {} }; class B : public A { public: void DoSomethingBLike() const {} }; void UseAnA(A const& some_A) { some_A.DoSomethingALike(); } void SomeFunc() { B b; UseAnA(b); // b can be substituted for an A. } </syntaxhighlight><ref name="Mitchell2002"> {{cite book | last=Mitchell | first=John | author-link=John C. Mitchell | title=Concepts in programming language | year=2002 | publisher=Cambridge University Press | location=Cambridge, UK | isbn=0-521-78098-5 | page=287 | chapter=10 "Concepts in object-oriented languages"}} </ref>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)