Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Default members generated by C++

Reply
Thread Tools

Default members generated by C++

 
 
BeautifulMind
Guest
Posts: n/a
 
      01-29-2007
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

 
Reply With Quote
 
 
 
 
Alf P. Steinbach
Guest
Posts: n/a
 
      01-29-2007
* 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?
 
Reply With Quote
 
 
 
 
lovecreatesbea...@gmail.com
Guest
Posts: n/a
 
      01-29-2007


On Jan 29, 3:32 am, "Alf P. Steinbach" <a...@start.no> 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
};

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Will array members be copied ok by compiler generated copy functions? newbarker@gmail.com C++ 1 01-13-2009 04:34 PM
Default class members generated by C++ BeautifulMind C++ 5 01-30-2007 12:38 PM
Difference between static final members and final static members(if any)? JFCM Java 4 02-07-2006 11:32 AM
Templates: Members Vs. non-members Dave C++ 3 08-10-2004 11:23 AM
Can nested class members access private members of nesting class? CoolPint C++ 8 12-14-2003 02:30 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57