C++ Constructor default parameter value

Description

C++ Constructor default parameter value

 
#include <iostream>
using namespace std;
class Complex//from www . jav  a  2 s.c  om
{
   private:
   double realPart;
   double imaginaryPart;
   public:
   Complex(double = 0.0, double = 0.0);  // constructor prototype with default arguments
};
// implementation section
Complex::Complex(double real, double imag)   // constructor
{
   realPart = real;
   imaginaryPart = imag;
   cout << "Created the new complex number object " << realPart << " + " << imaginaryPart << "i\n";
}
int main()
{
   Complex a;             // declare an object
   Complex b(6.8, 9.7);    // declare an object
   return 0;
}



PreviousNext

Related