Implicitly declared/defined member functions and inheritance

  • Thread starter lovecreatesbeauty
  • Start date
L

lovecreatesbeauty

The following shortened table comes from a big company's C++ technical
document accompanied with its C++ compiler. This company's C++ compiler
was/is very popular in Windows platform programming. But I'm not sure
whether this table is accurate.

The language standard says "Operator functions are inherited", I guess
that it means all operator functions are inherited. But that table says
operator = is not. Is operator = an exception?

Could you please give me a another correct list to explain:

1. which member functions can be declared and/or defined implicitly?

2. which member functions can't be inherited in derived class?


Thank you.



-- Quotation 1 ---------------------------------------

--------------- inheritable ? -- provided implicitly ?

------------------------------------------------------

constructor -------- no ---------------- yes ---------

copy constructor --- no ---------------- yes ---------

destructor --------- no ---------------- yes ---------

operator = --------- no ---------------- yes ---------

-- Quotation 1 ends ----------------------------------



-- Quotation 2: ISO/IEC 14882 ---------------

13.5 Overloaded operators

6 ...The meaning of the operator = , (unary) &, and , (comma),
predefined for each type, can be changed for specific class and
enumeration types by defining operator functions that implement these
operators. Operator functions are inherited in the same manner as other
base class functions.
....
-- Quotation 2 ends -------------------------
 
I

Ioannis Vranos

lovecreatesbeauty said:
The following shortened table comes from a big company's C++ technical
document accompanied with its C++ compiler. This company's C++ compiler
was/is very popular in Windows platform programming. But I'm not sure
whether this table is accurate.

The language standard says "Operator functions are inherited", I guess
that it means all operator functions are inherited. But that table says
operator = is not. Is operator = an exception?


Are you talking about C++/CLI and .NET 2? In .NET the base Object class has its operator=
disabled (private). If you define it as public in one of your classes, then all of your
derived classes of it, will also have operator=. C#/CLI on the other hand, "magically"
comes with an implicit operator= for user-defined classes, C++ however preserves this
semantics.
 
J

Jack Klein

Are you talking about C++/CLI and .NET 2?

If he is, he is off-topic here, just as your reply is.

Kindly keep your ramblings about yet another non-standard extension
out of this group.
 
I

Ioannis Vranos

Jack said:
If he is, he is off-topic here, just as your reply is.

Kindly keep your ramblings about yet another non-standard extension
out of this group.


Actually it is a standardised *extension* to C++2003. :) Not part of ISO C++ though,
however some features of C++/CLI *will* become part of the core C++0x in the future, and
also it describes how C++ can interact with a VM.

Also the parts of it does not include any Forms, TextBoxes, etc that you may be afraid of,
any API usage is considered system-specific there too, the additional facilities provided
are minimal (actually apart from the Console class and String type I can't remember
something more).


Of course, the majority of the regulars will decide what will be topical here in the
future, however there can't be another newsgroup for C++/CLI, because it is ISO C++
extensions and can not "live" without ISO C++.
 
L

lovecreatesbeauty

Vranos, you can post another thread to talk about what you'er talking
about.

I want to know, in C++ (ISO/IEC 14882:1998):

1. For a class, which member functions can be declared/defined
implicitly.

2. Which base class members can't be inherited in derived class.
 
I

Ioannis Vranos

lovecreatesbeauty said:
Vranos, you can post another thread to talk about what you'er talking
about.

I want to know, in C++ (ISO/IEC 14882:1998):

1. For a class, which member functions can be declared/defined
implicitly.


When you create a class SomeClass, an assignment operator and a copy constructor are
created implicitly which provide shallow copying (all data members are copied value-wise),
also a "default" constructor doing nothing ( SomeClass() ) and a "default" destructor
doing nothing.

2. Which base class members can't be inherited in derived class.


Everything is inherited (and can be disabled). Perhaps you may clarify what you mean with
"inherited".
 
L

lovecreatesbeauty

------- quotation: ISO/IEC 14882 -------

10.3 Virtual functions

4. Even though destructors are not inherited, a destructor in a
derived overrides a base class destructor declared virtual;
....


12.3.2 Conversion functions

5. Conversion functions are inherited.


13.5 Overloaded operators

6. ...The meaning of the operator = , (unary) &, and , (comma),
predefined for each type, can be changed for specific class and
enumeration types by defining operator functions that implement these
operators. Operator functions are inherited in the same manner as other
base class functions.

------- quotation ends -------

I've be taught that constructors, destructor and copy assignment are
not inherited from base classes in derived classes. As for these
members, derived classes will always have its own members instead of
inherit them from father classes.

But I don't find a complete list of these members from the language
standard.

Thank you.
 
L

lovecreatesbeauty

I found that Bruce Eckel talked about this topic in his `thinking in
C++, 2nd` section 14.

regards
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,049
Latest member
Allen00Reed

Latest Threads

Top