O'Reilly logo

C++11 for Programmers, Second Edition by Harvey M. Deitel, Abbey Deitel, Paul J. Deitel

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Accidentally Using a Single-Argument Constructor as a Conversion Constructor

The program (Fig. 10.12) uses the Array class of Figs. 10.1010.11 to demonstrate an improper implicit conversion. To allow this implicit conversion, we removed the explicit keyword from line 14 in Array.h (Fig. 10.10).

 1   // Fig. 10.12: fig10_12.cpp 2   // Single-argument constructors and implicit conversions. 3   #include <iostream> 4   #include "Array.h"  5   using namespace std; 6  7   void outputArray( const Array & ); // prototype 8  9   int main()10   {11      Array integers1( 7 ); // 7-element Array12      outputArray( integers1 ); // output Array integers113      outputArray( 3 ); // convert 3 to an Array and output Array's contents ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required