STL: how to overload operator= for <vector> ?
Posted
by MBes
on Stack Overflow
See other posts from Stack Overflow
or by MBes
Published on 2010-02-03T15:40:08Z
Indexed on
2010/04/10
18:33 UTC
Read the original article
Hit count: 174
There's simple example:
#include <vector>
int main() {
vector<int> veci;
vector<double> vecd;
for(int i = 0;i<10;++i){
veci.push_back(i);
vecd.push_back(i);
}
vecd = veci; // <- THE PROBLEM
}
The thing I need to know is how to overload operator = so that I could make assignment like this:
vector<double> = vector<int>;
I've just tried a lot of ways, but always compiler has been returning errors...
Is there any option to make this code work without changing it? I can write some additional lines, but can't edit or delete the existing ones. Ty.
© Stack Overflow or respective owner