Default members generated by C++

B

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
 
A

Alf P. Steinbach

* 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.
 
L

lovecreatesbea...

* BeautifulMind:
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
};
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top