axyd icon

C++ Create Many Objects

axyd | PRO | 10/25/16 06:31:20 AM UTC | 0 ⭐ | 717 👁️ | Never ⏰ | []
C++ |

500 B

|

None

|

0 👍

/

0 👎

#include <iostream>
#include <vector>
using namespace std;
 
class Xclass {
    public:
        Xclass() {}
        ~Xclass() {}
        string y;
        int x;
};
 
int main(int argc, char** argv) {
    vector<Xclass> vx;
    int a=1000;
    int ktr=0;
    while(a>0) {    //create 1000 objects of class Xclass
        Xclass xc;
        vx.push_back(xc);
        cout<<a<<endl;
        --a;
        ktr++;
    }
 
    vx.at(2).x=999; //set value to 3rd object.
 
    cout<<"\nKTR: "<<ktr<<" Vector Size: "<<vx.size()<<" Vector[2].x val: "<<vx.at(2).x<<endl;
    return 0;
}

Comments