I'm new with C++ OOP. Seems that in my simple code i'm not passing correctly an argument to the constructor of my class. Where's the error?
This is the class that i've defined
class Bandiera
{
private:
vector<string> colori;
public:
Bandiera(vector<string> c)
{
colori = c;
}
bool biancoPresente()
{
for (short i = 0; i < colori.size(); i++)
if (colori[i] == "bianco")
return true;
return false;
}
bool rossoPresente()
{
for (short i = 0; i < colori.size(); i++)
if (colori[i] == "rosso")
return true;
return false;
}
bool colorePresente(string nomeColore)
{
for (short i = 0; i < colori.size(); i++)
if (colori[i] == nomeColore)
return true;
return false;
}
};
And this is my main:
int main()
{
map<string, Bandiera> mappaColoriBandiere;
ifstream f("bandiere.txt");
string buffer, nomeNazione, colore;
vector<string> bufferColori;
while (getline(f, buffer))
{
stringstream ss(buffer);
ss >> nomeNazione;
while (!ss.eof())
{
ss >> colore;
bufferColori.push_back(colore);
}
Bandiera b(bufferColori);
mappaColoriBandiere[nomeNazione] = b;
bufferColori.clear();
}
map<string, Bandiera>::iterator it;
for (it = mappaColoriBandiere.begin(); it != mappaColoriBandiere.end(); it++)
if (it->second.biancoPresente() && it->second.rossoPresente())
cout << it->first << endl;
return 0;
}
Take for correct the part of the code where I read data from the ifstream. The error the is given bakc to me is this one:
c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\tuple:1586:70: error: no matching function for call to 'Bandiera::Bandiera()'
second(std::forward<_Args2>(std::get<_Indexes2>(__tuple2))...)
^
bandiere.cpp:14:5: note: candidate: Bandiera::Bandiera(std::vector<std::__cxx11::basic_string<char> >)
Bandiera(vector<string> c)
^~~~~~~~
bandiere.cpp:14:5: note: candidate expects 1 argument, 0 provided
bandiere.cpp:8:7: note: candidate: Bandiera::Bandiera(const Bandiera&)
class Bandiera
^~~~~~~~
bandiere.cpp:8:7: note: candidate expects 1 argument, 0 provided
bandiere.cpp:8:7: note: candidate: Bandiera::Bandiera(Bandiera&&)
bandiere.cpp:8:7: note: candidate expects 1 argument, 0 provided
Edit 1 Thanks for all the answers, they were almost perfect. My code works perfectly fine just adding the Defualt constructor to my class. The thing is that my code should be good also adding a copy constructor like this one
Bandiera(const Bandiera &b)
{
colori = b.colori;
}
but it gives me the same error as the initial one. Hope someone can explain this to me. Thanks