C++ Pointer Dereferencing the pointer returned by new

Description

C++ Pointer Dereferencing the pointer returned by new

#include <iostream>
using namespace std;
class Measure                    // English Measure class
{
   private://from w ww  . jav a  2 s .  com
   int feet;
   float inches;
   public:
   void getdist()              // get length from user
   {
      cout << "\nEnter feet: ";  cin >> feet;
      cout << "Enter inches: ";  cin >> inches;
   }
   void showdist()             // display distance
   { cout << feet << "\'-" << inches << '\"'; }
};
int main()
{
   Measure& dist = *(new Measure);  // create Measure object
   // alias is "dist"
   dist.getdist();                    // access object members
   dist.showdist();                   //    with dot operator
   cout << endl;
   return 0;
}



PreviousNext

Related