Incrementing an object pointer
#include <iostream>
using namespace std;
class MyClass {
int num;
public:
void set_num(int val) {num = val;}
void show_num();
};
void MyClass::show_num()
{
cout << num << "\n";
}
main(void)
{
MyClass ob[2], *p;
ob[0].set_num(10);
ob[1].set_num(20);
p = &ob[0];
p->show_num();
p++;
p->show_num();
p++;
p->show_num();
return 0;
}
Related examples in the same category