Reputation: 207
In header file, I declared the following as a public member variable:
vector< vector<unsigned char> > arImage;
In source code, I define temp
vector<vector<unsigned char> > temp (numImage, vector<unsigned char>(sizeImage));
Now I try to ,
temp.swap(arImage);
But an error occured. (detail errors are omitted because they are not English)
with
[
_Ty=std::vector<unsigned char>
]
//////////// Addition,,,,,,,,
I want to swap
vector<vector<unsigned char> > to vector<vector<unsigned char> >
I'm working with MFC. I can't find proper method, so I actually take another approach.
In header file,
vector< vector<unsigned char> > * arImage;
In source code,
arImage = new vector< vector<unsigned char> > (numImage, vector<unsigned char>(sizeImage));
But this approach is not comfortable.(this approach is no error)
I want to use arImage[i][j].
In this approach, I have to use (*arImage)[i][j]
Upvotes: 1
Views: 246
Reputation: 1050
The thing you are doing wrong here is you are trying to swap vector< unsigned char >
with vector of vector< unsigned char >
which is not possible.
Vector arImage
has items of type unsigned char
while temp type is vector<vector<unsigned char> >
so temp items are vector<unsigned char>
.
So it make sense as can not swap vector<unsigned char>
with unsigned char
. Similarly you can not swap vector< unsigned char >
with vector <vector< unsigned char >>
.
I hope it explains everything.
Upvotes: 3
Reputation: 5546
You have to choose index which have to be swaped in your temp
:
int index = 0;
temp[index].swap(arImage);
You declared temp as vector of vectors (2D). So swapping will perform with the same type of variable (which is logical). But you try to swap with 1D vector what is wrong, that's what compiler says to you.
Upvotes: 3