// intro to pointers to objects // Mikhail Nesterenko // 11/4/99 #include using namespace std; class myclass{ public: int getval() { return data; } void setval(int v){ data=v; } void add1() { data++; } private: int data; }; int main(){ myclass ob, *obp; obp=&ob; ob.setval(1); // calling a member function (*obp).setval(2); // calling a member function // using a pointer // parentheses are there // because object accessor (.) // has higher prefernce than // dereference (*) obp->setval(2); // more accepted way of accessing // a member function // or variable cout << "The value stored is: " << obp->getval() << endl; for(; obp->getval() < 5; obp->add1()) cout << "New value is: " << obp->getval() << endl; }