4

I've been asked to name three things that can not be inherited from the base class.

Apart from private member functions, what else can I add?

I thought about friend functions but since they don't actually belong to the class, they have nothing to do with inheritance.

7
  • 5
    "private functions with names starting with 'n'", "private functions with names starting with 'o'", and "private functions with names not starting with 'n' or 'o'" :P Jun 8, 2012 at 4:55
  • @R.MartinhoFernandes, can you elaborate more ? lolz
    – Amit
    Jun 8, 2012 at 4:57
  • @R.MartinhoFernandes: Could'nt quite understand... lolz.. :) Jun 8, 2012 at 4:58
  • I think constructors are destructors are also not inherited ... is that the reason we need to call base class's version separately ???
    – Amit
    Jun 8, 2012 at 4:59
  • @anDroider Constructors and destructors can be inherited.
    – Max
    Jun 8, 2012 at 5:02

2 Answers 2

8

A few obvious ones you usually care about are constructors, assignment operators and destructors.

In all these cases, a new version specific to the derived class is either provided by the user, or else synthesized by the compiler (though C++11 also adds some capabilities for things like simply deleting one that you don't want available).

I should probably add that "can not be inherited" isn't necessarily exactly correct. For example, C++11 adds inheriting constructors (but they weren't in C++98/03, which is what most courses still deal with). Even in C++11, you don't inherit them by default.

0

Private member variables, and private bases. You also cannot inherit template arguments, COM __uuids, and whether or not the class is exported from a DLL.

Assignment operators cannot be inherited.

14
  • 3
    I think you're wrong, private member variables are inherited, but derived classes cannot access them directly.
    – Max
    Jun 8, 2012 at 5:04
  • @crazyffan: So just add "Ability to access" in front. Besides, I provided more than that.#
    – Puppy
    Jun 8, 2012 at 5:11
  • 1
    @crazyfffan: Well, I would think so, but only an idiot lecturer would ask such a question, so who knows?
    – Puppy
    Jun 8, 2012 at 5:18
  • 2
    @DeadMG: also, I don't think it's reasonable to call the lecturer an idiot. No doubt the lecture (or other course materials) about inheritance included examples of things that are inherited, and things that are not. The purpose of the question is to see whether the student has learned the course materials, no? It's pretty common for programmers to insult educators, on the basis that educators do things other than write profit-making code, but I think that's misguided. Better-guided would be to insult educators only if their students emerge unable to write code. Which is frequent! Jun 8, 2012 at 9:02
  • 2
    @DeadMG: that's exactly what I mean, criticising educators for doing anything other than writing "actual code". You think it's a waste of students' time to be given examples of things that are or are not inherited. I don't really see how else you could competently teach somebody what inheritance in C++ does. Read out all the relevant passages from the standard, I suppose. The reason I didn't answer isn't that I've never needed to know any of this, it's that I think Jerry's answer is fine, and yours is amusing. I don't have more examples to add. Jun 8, 2012 at 9:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.