I got one code:
There is pointer which points to class "objekat". Also there are functions which define and print the private variable "test".Code:#include <iostream> using namespace std; class objekat { int test; public: void definiraj_test(int a){ test=a; }; void pecati_test(){ cout<<test<<endl;} }; int main() { objekat *pokazuvac; pokazuvac = new objekat; for(int i=0;i<5;i++) { pokazuvac[i].definiraj_test(i); } for(int i=0;i<5;i++) { pokazuvac[i].pecati_test(); } system("PAUSE"); }
First I declare the pointer objekat *pokazuvac;. Then pokazuvac = new objekat;.
Now the pointer points to one object. But what if I do something like:
Why it still works? The pointer points to one object, and not array of objects??Code:for(int i=0;i<5;i++) { pokazuvac[i].definiraj_test(i); }
Thanks in advance.




Reply With Quote
