This question is related to pointers and objects. I have commented out my issue.
#include<iostream> #include<conio.h> using namespace std; class item { int code; float price; public: void getData(int a, float b) { code=a; price=b; } void show(void) { cout<<"Code: "<<code<<"\n"; cout<<"price: "<<price<<"\n"; } }; const int size=2; int main() { item *p=new item[size]; //defining an array of objects or pointers to objects; item *d=p; //what does this mean? int x, i; float y; for(int i=0; i<size; i++) { cout<<"Input code and price for item "<<i+1; cin>>x>>y; p->getData(x,y); p++; } for(int i=0; i<size; i++) { cout<<"Item: "<<i+1<<"\n"; d->show(); //I tried swapping d with p, thinking they must represent same address d++; //but it gave improper output. I am obliged to use d++ } return 0; }