vector<Sample> samples;
samples.push_back(sample1);
samples.push_back(sample2);
After this, the size of samples
is 2. So you can only access samples[0]
and samples[1]
, not samples[2]
.
As commented by @sammy, variables in Watch
may show incorrect values in VS.
To make it work, you may want to follow the following steps:
- Check if the application and its dependencies (if required) are built in debug mode.
- Ensure the Optimization is disable. Use the
/Od
option when compiling. - Struct Member Alignment. When there are a bunch of projects compiled together, with varying values for this field inside the projects could cause invalid display values. Reset to Default value on all of the projects.The value is under Configuration Properties-> C/C++ ->Code Generation -> Struct Member Alignment.
Check out here for more info.
Edit: For your code in the comment:
sample1.classlabel[0] = 0;
sample1.classlabel[1]=1;
vector<Mat> temp;
temp.push_back(img1);
temp.push_back(img2);
temp.push_back(img3);
sample1.image=temp;
sample2.classlabel[0] = 0;
sample2.classlabel[1]=1;
vector<Mat> temp1;
temp.push_back(img5); // problem
temp.push_back(img6); // problem
temp.push_back(img7); // problem
sample2.image=temp1;
samples.push_back(sample1);
samples.push_back(sample2);
The 3 problem lines should change to
temp1.push_back(img5);
temp1.push_back(img6);
temp1.push_back(img7);