-1

A point from C++11 n3242 "Duration of subobjects, object lifetime", 3.8/1:

The lifetime of an object is a runtime property of the object. An object is said to have non-trivial initialization if it is of a class or aggregate type and it or one of its members is initialized by a constructor other than a trivial default constructor [ Note: initialization by a trivial copy/move constructor is non-trivial initialization. — end note ]

The lifetime of an object of type T begins when:

  • storage with the proper alignment and size for type T is obtained, and
  • if the object has non-trivial initialization, its initialization is complete.

The lifetime of an object of type T ends when:

  • if T is a class type with a non-trivial destructor (12.4), the destructor call starts, or
  • the storage which the object occupies is reused or released.

Here they said about trivial or nontrivial copy/move constructor with object lifetime. Can any one explain this with some example program?

And the change of an point describes when the lifetime of an object of type T begins, but they didn't mention when T ends. Why?

RobH
  • 3,199
  • 1
  • 22
  • 27
user751747
  • 1,129
  • 1
  • 8
  • 17
  • 3
    You've asked question after question about examples for quotes from the standard. May I suggest [a great C++ book instead](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list)? This is not the way to learn C++, and SO is not a good fit for these questions (IMO). Also, in English, the space comes _after_ the comma, and after 32 questions I think it's time you started phrasing your questions with well-formed sentences, rather than snippets of words and lots of extraneous punctuation! – Lightness Races in Orbit Sep 27 '11 at 07:10
  • @ Tomalak : thanks for your valuable advice .here iam trying to understand the new concepts(not only basic parts .. but with whole c++ standard..so i opted c++ standard ...it won't neglect ..a a single word ...)...how it actually modified/added to c++0x ,when compared to c++03. – user751747 Sep 27 '11 at 07:16
  • 2
    Again, the standard is not a good way to learn C++ concepts, be they new or not. – Lightness Races in Orbit Sep 27 '11 at 07:22
  • Learning by doing works better than learning by reading. For such questions it is _especially_ useful if you'd write some code yourself first. If you still have questions, you can post that code which lead to those questions. – MSalters Sep 27 '11 at 09:05
  • @MSalters : I triend for C++0x concepts book . but i came to know the conclusion it is the useless work... "C++[01]x isn't even out yet. How can you seek for a book then :) I guess the best book is the current working draft: ..... sail by users..." this is the statement ... i got form this link http://stackoverflow.com/questions/404318/good-book-recommendation-for-c0x so ..i liked this idea .... and iam following the same .. – user751747 Sep 27 '11 at 11:39
  • @user751747: That's still no excuse for your lack of grammar. You could at least make an attempt at proper punctuation. Ellipsis (...) are not the same as a period (.); just look at how everyone else types and try to follow that. – Nicol Bolas Sep 27 '11 at 19:16

2 Answers2

2

Here they said about trivial or nontrivial copy/move constructor with object lifetime. Can any one explain this with some example program?

It's just semantics. In all cases, this can be translated to "the object's lifetime begins when the constructor has finished running". The quote is just being thorough because trivial construction doesn't really involve any such execution.

It's not easy to give an "example" of this point; I could show you trivial and non-trivial constructors, but it wouldn't really tell you anything so I'm not going to.

And the change of an point describes when the lifetime of an object of type T begins, but they didn't mention when T ends. Why?

Yes they did. It should be clearer now that I reformatted the quote in your question.

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
1

In general an object is alive when its constructor has run to completion and lives until the start of its destructor.

An exception is types that are so trivial that there is no constructor run for them, for example after the code

int* p = (int*)malloc(1024);

you have a bunch of ints that are alive, even though they are not initialized in any way and no constructors have been executed. Still, they are there and you can assign them values.

Bo Persson
  • 90,663
  • 31
  • 146
  • 203
  • in fact the spec says we have a bunch of ints and floats and doubles in that same memory array :) aliasing rules? pfft :) If it only were coherent about it. – Johannes Schaub - litb Oct 01 '11 at 23:54