Which members are created automatically, which members are not inherited?

Discussion in 'C++' started by lovecreatesbeauty, Jan 26, 2006.

  1. I'm disturbed on this question on a long time. I think if I finally get
    understand it with your kind help, I will get close to a excellent C++
    programmer. And I only can rely on your expertise and help. I've read
    some books, but no book focuses on this. Don't you think it is a very
    important thing of C++ programming language? So your knowledge is of
    great benefit to others, especially me.


    1. Which (How many) members will be created automatically?

    Scott Meyers seems to give this list in a early print of his
    <<effective C++, 2nd>>, but he removed 1 (or 2, perhaps you know it),
    the list containing 6 members he gives is:

    default constructor, copy constructor, destructor, assignment
    operator, a pair of address-of operators (i.e. const, non-const) .

    But in a later print (not a new edition, I don't read the 3rd one) he
    removed the last pair of operators from that list without a detail
    description, or he put that pair in that list before without a
    thoroughly convinced reason. That is my complaint.

    Dr. Bjarne Stroustrup mentioned operator , (i.e. comma) is also a
    predefined member (he mentioned total 3: =, &, and , in TC++PL sec
    11.2.2), but Andrew Koenig said "That is not a member function." in my
    post before. Obviously, it is inside a class body, so I do not
    understand what he said.

    Herb Sutter mentioned &&, || and , (comma) in his new book C++ coding
    standard. But he did not give a complete list of automatically created
    class members also. He always talks about some magic things on usage of
    vector, list or some similar things with gurus. That is my complaint.

    How about new and delete, and some others functions or operators which
    I do not know the name. Who will give a complete list?


    2. Which (How many) members can not be inherited?

    I know default ctor, copy ctor, dctor, assignment operator can not be
    inherited. The first three members share the same name respectively
    even the base class name and the derived class name are different - it
    is obvious, but it helps me to understand the reason of non-inherited.
    I can understand operator assignment will not be inherited also.

    But I am not sure if there are other members also can not be inherited.

    How about new and delete, and some others functions or operators which
    I do not know the name. Who will give a complete list?


    Sincerely,

    lovecreatesbeauty
     
    lovecreatesbeauty, Jan 26, 2006
    #1
    1. Advertising

  2. Re: Which members are created automatically, which members are notinherited?

    lovecreatesbeauty wrote:
    > I'm disturbed on this question on a long time. I think if I finally get
    > understand it with your kind help, I will get close to a excellent C++
    > programmer. And I only can rely on your expertise and help. I've read
    > some books, but no book focuses on this. Don't you think it is a very
    > important thing of C++ programming language? So your knowledge is of
    > great benefit to others, especially me.
    >
    >
    > 1. Which (How many) members will be created automatically?
    >
    > Scott Meyers seems to give this list in a early print of his
    > <<effective C++, 2nd>>, but he removed 1 (or 2, perhaps you know it),


    Why don't you "know it"? Doesn't your nearby library have both books?

    > the list containing 6 members he gives is:
    >
    > default constructor, copy constructor, destructor, assignment
    > operator, a pair of address-of operators (i.e. const, non-const) .
    >
    > But in a later print (not a new edition, I don't read the 3rd one) he
    > removed the last pair of operators from that list without a detail
    > description, or he put that pair in that list before without a
    > thoroughly convinced reason. That is my complaint.


    You should contact Scott, then. If it's a complaint, I mean. You know,
    Scott is available on Internet...

    > Dr. Bjarne Stroustrup mentioned operator , (i.e. comma) is also a
    > predefined member (he mentioned total 3: =, &, and , in TC++PL sec
    > 11.2.2), but Andrew Koenig said "That is not a member function." in my
    > post before. Obviously, it is inside a class body, so I do not
    > understand what he said.


    What _who_ said? Koenig or Stroustrup?

    > Herb Sutter mentioned &&, || and , (comma) in his new book C++ coding
    > standard. But he did not give a complete list of automatically created
    > class members also. He always talks about some magic things on usage of
    > vector, list or some similar things with gurus. That is my complaint.
    >
    > How about new and delete, and some others functions or operators which
    > I do not know the name. Who will give a complete list?


    The complete list is conditional. For example, if you have any
    parameterised c-tor, the default c-tor is not generated. Assignment op
    is not generated if there are members that don't allow that...

    > 2. Which (How many) members can not be inherited?
    >
    > I know default ctor, copy ctor, dctor, assignment operator can not be
    > inherited. The first three members share the same name respectively
    > even the base class name and the derived class name are different - it
    > is obvious, but it helps me to understand the reason of non-inherited.
    > I can understand operator assignment will not be inherited also.


    No constructors are inherited. Ever.

    Virtualness of the destructor is an inherited trait.

    The _copy_ assignment op is not inherited. Parameterized can be.

    > But I am not sure if there are other members also can not be inherited.
    >
    > How about new and delete, and some others functions or operators which
    > I do not know the name. Who will give a complete list?


    I don't think there is a complete and hard-set list. It's all relative.

    V
     
    Victor Bazarov, Jan 26, 2006
    #2
    1. Advertising

  3. lovecreatesbeauty

    TB Guest

    Re: Which members are created automatically, which members are notinherited?

    lovecreatesbeauty sade:
    > I'm disturbed on this question on a long time. I think if I finally get
    > understand it with your kind help, I will get close to a excellent C++
    > programmer. And I only can rely on your expertise and help. I've read
    > some books, but no book focuses on this. Don't you think it is a very
    > important thing of C++ programming language? So your knowledge is of
    > great benefit to others, especially me.
    >
    >


    <snipped Scott Meyers>
    <snipped Bjarne Stroustrup>
    <snipped Andrew Koenig>
    <snipped Herb Sutter>

    Why not enter the next level and buy a copy of the standard?
    ISBN: 0470846747
    That way you won't need to flip through several books to
    find hidden hints/answers about language features, just one.

    --
    TB @ SWEDEN
     
    TB, Jan 26, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    4
    Views:
    390
    Siemel Naran
    May 20, 2004
  2. Simon White
    Replies:
    2
    Views:
    372
    Sharad Kala
    Jun 16, 2004
  3. lovecreatesbeauty
    Replies:
    43
    Views:
    1,322
    Keith Thompson
    Feb 6, 2006
  4. Cirene
    Replies:
    1
    Views:
    318
    Cirene
    Sep 16, 2008
  5. 7stud --
    Replies:
    11
    Views:
    469
    7stud --
    Nov 9, 2007
Loading...

Share This Page