Mi da questo errore:..\citta.cpp:10:22: error: ambiguous overload for 'operator=' (operand types are 'std::__cxx11::string {aka std::__cxx11::basic_string<char>}' and 'int')
nome=codice=regione=0;
^
In file included from c:\mingw\include\c++\7.2.0\string:52:0,
from c:\mingw\include\c++\7.2.0\bits\locale_classes.h:40,
from c:\mingw\include\c++\7.2.0\bits\ios_base.h:41,
from c:\mingw\include\c++\7.2.0\ios:42,
from c:\mingw\include\c++\7.2.0\ostream:38,
from c:\mingw\include\c++\7.2.0\iostream:39,
from ..\citta.cpp:5:
c:\mingw\include\c++\7.2.0\bits\basic_string.h:627:7: note: candidate: std::__cxx11::basic_string<_CharT, _Traits, _Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::operator=(const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]
operator=(const basic_string& __str)
^~~~~~~~
c:\mingw\include\c++\7.2.0\bits\basic_string.h:666:7: note: candidate: std::__cxx11::basic_string<_CharT, _Traits, _Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::operator=(const _CharT*) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]
operator=(const _CharT* __s)
^~~~~~~~
c:\mingw\include\c++\7.2.0\bits\basic_string.h:677:7: note: candidate: std::__cxx11::basic_string<_CharT, _Traits, _Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::operator=(_CharT) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]
operator=(_CharT __c)
^~~~~~~~
c:\mingw\include\c++\7.2.0\bits\basic_string.h:695:7: note: candidate: std::__cxx11::basic_string<_CharT, _Traits, _Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::operator=(std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]
operator=(basic_string&& __str)
^~~~~~~~
file.h:
#include <list>
using namespace std;
class Citta {
string nome;
string regione;
string codice;
list<int> temperature;
public:
Citta();
Citta(const Citta &c);
Citta& operator=(const Citta &c);
bool operator<(Citta &o);
friend ostream& operator<<(ostream &os, const Citta &c);
friend istream& operator>>(istream &is, Citta &c);
// Funzioni SET
void setNome(const string n){nome=n;}
void setRegione(const string c){regione=c;}
void setCodice(const string m){codice=m;}
// Funzioni GET
string getNome()const{return nome;}
string getRegione()const{return regione;}
string getCodice()const{return codice;}
// Altre Funzioni
void addTemperatura(int t); // aggiunge una nuova temperatura alla lista delle temperature
void clear(); // azzera la lista delle temperature
int mediaTemperature()const; // calcola e restituisce la media delle temperature
};
file.cpp:
#include <iostream>
#include "citta.h"
using namespace std;
Citta::Citta(){
nome=codice=regione=0;
}
Citta::Citta(const Citta &c){
nome=c.getNome();
regione=c.getRegione();
codice=c.getCodice();
temperature=c.temperature;
}
Citta& Citta::operator=(const Citta &c){
if(&c!=this){
setNome(c.nome);
setRegione(c.regione);
setCodice(c.codice);
temperature=c.temperature;
}
return *this;
}
bool Citta:: operator<(Citta &o){
return (mediaTemperature()<o.mediaTemperature());
}
ostream& operator<<(ostream &os, const Citta &c){
os<<c.nome<<",";
os<<c.regione<<",";
os<<c.codice<<",";
int n=c.temperature.size();
os<<n<<" ";
list<int>::const_iterator it;
for(it=c.temperature.begin(); it!=c.temperature.end(); ++it){
os<<" "<<*it;
}
os<<endl;
return os;
}
istream& operator>>(istream &is, Citta &c){
int tmp;
getline(is,c.nome,',');
getline(is,c.regione,',');
getline(is,c.codice,',');
int n=c.temperature.size();
is>>n;
c.temperature.clear();
for(int i=0; i<n; i++){
is>>tmp;
c.temperature.push_back(tmp);
}
is.ignore();
return is;
}
void Citta::addTemperatura(int t){
temperature.push_back(t);
}
void Citta::clear(){
temperature.clear();
}
int Citta::mediaTemperature()const{
int n=temperature.size();
int m=0;
list<int>::const_iterator it;
for(it=temperature.begin(); it!=temperature.end(); ++it){
m+=*it;
}
return (m/n);
}