Home > DeveloperSection > Forums > How to create a array of objects in c ?
jayprakash sharma
jayprakash sharma

Total Post:117

Points:821
Posted on    June-14-2013 9:40 AM

 Visual C++ Visual C++ 
Ratings:


 1 Reply(s)
 549  View(s)
Rate this:
Hi,

How to create a array of objects in c++?

Thanks in advance. 


AVADHESH PATEL

Total Post:604

Points:4228
Posted on    June-15-2013 4:51 AM

Hi,

try this:

class sample{
int a;
public:
void set_a(int n) {a=n;}
int get_a( ) {return a}
};
int main()
{
sample ob[4];
int i;
for(i=0;  i<4;  i++) ob[i].set_a(i);
for(i=0; i<4; i++) cout<< ob[i].get_a( );
cout<<" \n";
return 0;
}

Don't want to miss updates? Please click the below button!

Follow MindStick