Pointer to object
//pointer to object
#include<iostream.h>
using namespace std;
class dist{
private:
int ft,in;
public:
dist():ft(0),in(0)
{}
dist(int f,int i):ft(f),in(i)
{}
void show()
{
cout<<ft<<" ' "<<in<<" '' "<<endl;
}
};
int main(int argc, char *argv[])
{
dist d1, d2(7,8);
d2.show();
dist* d;
d=new dist(7,9);
d->show();
(*d).show();
delete d;
d->show();
dist& d3=*(new dist);
d3.show();
//d3 is reference variable
//new dist create new
return 0;
}
Comments
Post a Comment