In C ++, I declare a custom class to store some values ββfor an object. Then I declare the vector of the specified object. Finally, I iterate over the vector to assign values ββto the fields.
#include <vector>
using namespace std;
class Custom
{
public:
int metric,nX,nY;
private:
};
int main( int argc, char** argv )
{
vector<Custom> MyWonderfulVector;
for(int i=0 ; i<10 ; i++){
MyWonderfulVector[i].metric = computation1();
MyWonderfulVector[i].nX= computation2();
MyWonderfulVector[i].nY= computation3();
}
return 0;
}
He throws out vector subscript out of rangewhen trying to evaluate MyWonderfulVector[i].metric = computation1();. metricis an int, computation1()too. in the first iteration, i = 0, so this should be fine. It is curious that in another place in the code I have a vector of another class (included in the library), and this syntax works for it, so I donβt understand why it does not work here.
EDIT:
Good with the comments that I changed to the following line: vector MyWonderfulVector (10);
, , ( Matlab;)). , , , _ "" . , , push_back temp . ...