Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Page 92, C++ primer 4th edition

Reply
Thread Tools

Page 92, C++ primer 4th edition

 
 
asdf
Guest
Posts: n/a
 
      11-21-2006
How to understand the last paragraph? Who'd like to give me an example?

There is a third possibility: The element type might be of a class type
that does not define any constructors. In this case, the library still
creates a value-initialized object. It does so by value-initializing
each member of that object.

 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      11-21-2006
asdf wrote:
> How to understand the last paragraph? Who'd like to give me an
> example?
>
> There is a third possibility: The element type might be of a class
> type that does not define any constructors. In this case, the library
> still creates a value-initialized object. It does so by
> value-initializing each member of that object.


Is this the paragraph you want to understand?

'Element', eh? Probably talking about arrays. Class that does not
define "any" constructors means that it has an implicitly-declared
and implicitly-defined (hopefully) default constructor (c-tor that
doesn't take any arguments). If it's defined (IOW, if all members
to be initialised *can* be initialised using default-initialisation),
then initialisation of an array [of objects] of such class will make
all elements of the array default-initialised.

class A { int a; public: A() : a() {} };
class B { A a; };

int main() {
B *pb = new B[10](); // ten elements, all value-initialised
}

In the example above, each 'a' of each 'B' will have it's 'a' set
to 0 (value-initialisation).

If this is not what the book is talking about, then you have to
explain what you're asking about, by quoting a bit more of the book.
I don't have a copy.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask


 
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
C++ Primer 4th edition, ex4.3.1-4.28 arnuld C++ 17 10-17-2006 09:29 PM
Page 572, C++ primer, 4th edition asdf C++ 3 10-11-2006 10:37 AM
page 293 of C++ primer,4th edition asdf C++ 6 09-18-2006 07:04 PM
C++ Primer, 4th Edition hajime C++ 5 08-16-2005 03:56 PM
Announcement: C++ Primer, 4th edition Andrew Koenig C++ 9 01-19-2005 11:17 PM



Advertisments