Default members generated by C++

Discussion in 'C++' started by BeautifulMind, Jan 29, 2007.

  1. Hi,
    As per the C++ standard, after the compilation of the following class
    "Test" how many / which members would be generated by the compiler.
    and actually I am also interested behind the logic doing so by C++ for
    this empty class "Test" which is not even utilized in the program.

    #include <iostream>
    using namespace std;

    class Test
    {
    };

    void main()
    {
    }

    Many Thanks
    BeautifulMind, Jan 29, 2007
    #1
    1. Advertising

  2. * BeautifulMind:
    > Hi,
    > As per the C++ standard, after the compilation of the following class
    > "Test" how many / which members would be generated by the compiler.
    > and actually I am also interested behind the logic doing so by C++ for
    > this empty class "Test" which is not even utilized in the program.
    >
    > #include <iostream>
    > using namespace std;
    >
    > class Test
    > {
    > };
    >
    > void main()
    > {
    > }
    >
    > Many Thanks


    The program has Undefined Behavior because 'main' has result type
    'void', which is not permitted.

    --
    A: Because it messes up the order in which people normally read text.
    Q: Why is it such a bad thing?
    A: Top-posting.
    Q: What is the most annoying thing on usenet and in e-mail?
    Alf P. Steinbach, Jan 29, 2007
    #2
    1. Advertising

  3. BeautifulMind

    Guest

    On Jan 29, 3:32 am, "Alf P. Steinbach" <> wrote:
    > * BeautifulMind:
    > > As per the C++ standard, after the compilation of the following class
    > > "Test" how many / which members would be generated by the compiler.
    > > and actually I am also interested behind the logic doing so by C++ for
    > > this empty class "Test" which is not even utilized in the program.

    >
    > > #include <iostream>
    > > using namespace std;

    >
    > > class Test
    > > {
    > > };


    > The program has Undefined Behavior because 'main' has result type
    > 'void', which is not permitted.


    (This is a reply to the original post, but I dont' have a copy of
    original post)

    For an empty class, the members in the following list will be created
    automatically or have predefined meanings. If the predefined versions
    of these members are not what you expect, you may override the
    corresponding members. These members are not inherited, for the child
    classes will have their own versions automatically. There should be
    some other members which will be provided automatically and are not
    inherited. For example `->', ...

    The following list comes from Bjarne Stroustrup's `The C++ Programming
    Language, special edition'. Please correct me in case I don't
    understand the programming language correctly,

    a) Operators cannot be overloaded (sec 11.2, TC++PL sp ed):

    :: (scope resolution)
    . (member selection)
    .* (member selection through pointer to member)

    :? (ternary conditional expression operator)
    sizeof
    typeid

    b) Operators have predefined meanings (sec 11.2.2, TC++PL sp ed):

    operator= (assignment, same as in sec 11.7)
    operator& (address-of)
    operator, (sequencing)

    c) Functions that control construction, destruction and copying (sec
    11.7, TC++PL sp ed)::

    class X
    {
    X(); // default constructor: create objects
    X(const X&); // copy constructor
    X& operator=(const X&); // copy assignment: cleanup and copy
    ~X(); // destructor: cleanup
    };
    , Jan 29, 2007
    #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. JFCM
    Replies:
    4
    Views:
    5,732
  2. CoolPint
    Replies:
    8
    Views:
    973
    Jeff Schwab
    Dec 14, 2003
  3. Dave
    Replies:
    3
    Views:
    363
    tom_usenet
    Aug 10, 2004
  4. hdixon
    Replies:
    3
    Views:
    637
    hdixon
    Jul 9, 2006
  5. BeautifulMind
    Replies:
    5
    Views:
    2,390
    Daniel T.
    Jan 30, 2007
Loading...

Share This Page