Inheritance

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Murali

    Inheritance

    Hi
    I have 2 questions.
    1) How do i make a class so that no other classes can't be derive from
    my class?
    2) Do i declare the constructor as private? Can any one explain when
    exactly it is useful?

    Thanks & Regards
    Murali

  • dasjotre

    #2
    Re: Inheritance

    On 27 Apr, 11:31, Murali <nalajala.mur.. .@gmail.comwrot e:
    Hi
    I have 2 questions.
    1) How do i make a class so that no other classes can't be derive from
    my class?
    2) Do i declare the constructor as private? Can any one explain when
    exactly it is useful?
    check FAQ


    I personally prefer

    class A // DON'T DERIVE FROM THIS !
    ...

    Comment

    • Rolf Magnus

      #3
      Re: Inheritance

      dasjotre wrote:
      On 27 Apr, 11:31, Murali <nalajala.mur.. .@gmail.comwrot e:
      >Hi
      >I have 2 questions.
      >1) How do i make a class so that no other classes can't be derive from
      >my class?
      >2) Do i declare the constructor as private? Can any one explain when
      >exactly it is useful?
      >
      check FAQ

      >
      I personally prefer
      >
      class A // DON'T DERIVE FROM THIS !
      ..
      I prefer letting the user of the class decide whether he finds it useful to
      derive from it.

      Comment

      • osmium

        #4
        Re: Inheritance

        "Rolf Magnus" writes:
        dasjotre wrote:
        >
        >On 27 Apr, 11:31, Murali <nalajala.mur.. .@gmail.comwrot e:
        >>Hi
        >>I have 2 questions.
        >>1) How do i make a class so that no other classes can't be derive from
        >>my class?
        >>2) Do i declare the constructor as private? Can any one explain when
        >>exactly it is useful?
        >>
        >check FAQ
        >http://www.parashift.com/c++-faq-lit...html#faq-23.11
        >>
        >I personally prefer
        >>
        >class A // DON'T DERIVE FROM THIS !
        >..
        >
        I prefer letting the user of the class decide whether he finds it useful
        to
        derive from it.
        Which is exactly what was proposed in the message you're responding to.
        Furthermore, it seems like good choice to me.


        Comment

        • James Kanze

          #5
          Re: Inheritance

          On Apr 29, 1:22 am, Rolf Magnus <ramag...@t-online.dewrote:
          dasjotre wrote:
          On 27 Apr, 11:31, Murali <nalajala.mur.. .@gmail.comwrot e:
          I have 2 questions.
          1) How do i make a class so that no other classes can't be derive from
          my class?
          2) Do i declare the constructor as private? Can any one explain when
          exactly it is useful?
          I personally prefer
          class A // DON'T DERIVE FROM THIS !
          ..
          I prefer letting the user of the class decide whether he finds it useful to
          derive from it.
          Which is, of course, very poor engineering. You can't write
          robust code if you don't know what it will be used for. If the
          requirement specifications state that the class will be used as
          a base class, you write it considerably differently than if they
          don't.

          --
          James Kanze (Gabi Software) email: james.kanze@gma il.com
          Conseils en informatique orientée objet/
          Beratung in objektorientier ter Datenverarbeitu ng
          9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

          Comment

          Working...