C++ examples for Class:Class Pointer
Dereferencing the pointer returned by new
#include <iostream> using namespace std; class Measure // English Measure class { private:/* w w w .ja va2 s. co m*/ 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; }