no match for ‘operator=

Hello, I have 2 files: Principal.cpp with the main() and Individuo.h

The individuo code is:

#include <iostream>
#include <vector>
#include <string>

using namespace std;
class Individuo{
public:
Individuo(string str1, string str2): factor{str1}, operacion{str2}
{ cout << "Initialised with " << factor[0] << " and " << operacion[0] << '\n'; }
void setFactor(string ftr)
{
factor = ftr;
}

private:
vector<string> factor;
vector<string> operacion;
};




throws an error message:

Individuo.h:17:12: error: no match for ‘operator=’ (operand types are ‘std::vector<std::__cxx11::basic_string<char> >’ and ‘std::__cxx11::string’ {aka ‘std::__cxx11::basic_string<char>’})
factor = ftr;
....

what is wrong with this file?

thanks
factor = ftr;

The quantity on the left-hand side, factor is a vector<string>.
The quantity on the right-hand side, ftr, is a string.

A vector<string> is NOT a string.

You need to decide what you want to do:
- set a string equal to a string?
- set a vector<string> equal to a vector<string>?
- push_back() a string into a vector<string>?

YOU need to decide what you want to do. One thing is plain, however: you cannot set one type of object equal to a completely different type of object.
Last edited on
Topic archived. No new replies allowed.