Item 36. Initialization

I l @ ve RuBoard

Difficulty: 3

What's the difference between direct initialization and copy initialization, and when are they used?

  1. What is the difference between direct initialization and copy initialization?

  2. Which of the following cases uses direct initialization, and which uses copy initialization?

     class T : public S { public:   T() : S(1),             // base initialization         x(2) {}           // member initialization   X x; }; T f( T t )                // passing a function argument {   return t;               // returning a value } S s; T t; S& r = t; reinterpret_cast<S&>(t);  // performing a reinterpret_cast static_cast<S>(t);        // performing a static_cast dynamic_cast<T&>(r);// performing a dynamic_cast const_cast<const T&>(t);  // performing a const_cast try {   throw T();              // throwing an exception } catch( T t )              // handling an exception { } f( T(s) );                // functional-notation type conversion S a[3] = { 1, 2, 3 };     // brace-enclosed initializers S* p = new S(4);          // new expression 
I l @ ve RuBoard


More Exceptional C++
More Exceptional C++: 40 New Engineering Puzzles, Programming Problems, and Solutions
ISBN: 020170434X
EAN: 2147483647
Year: 2001
Pages: 118
Authors: Herb Sutter

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net