ifstream Din;
cout << "do you want to load monster from a file? enter Y to continue";
cin >> load;
if (load == 'Y' || load == 'y')
{ifstream Din;
Din.open("monster.txt");
if (!Din)
{
cout << "Error!";
}
else
readFile(monster1,Din);
readFile(monster2,Din);
readFile(monster3,Din);
readFile(monster4,Din);
readFile(monster5,Din);
readFile(monster6,Din);
readFile(monster7,Din);
readFile(monster8,Din);
Din.close();
}
void readFile(Monster M, ifstream & Din)
{
Din >> M.getType() >> M.getPower() >> M.getGold() << endl;
}
/cygdrive/I/programming/ListDemo.cpp: In function `void readFile(Monster, std::ifstream&)':
/cygdrive/I/programming/ListDemo.cpp:133: error: no match for 'operator>>' in 'Din >> Monster::getType()()'
You have two ifstream Din. Remove the first one.
Pass Monster M as a reference, otherwise you're changing an object which get's destructed at the end of readFile().
Put brackets around the readFile() calls.
Use an array (or vector) of objects instead of 8 distinct variable.
Why did you put << endl after the inputs? Remove it.
What does Monster::getType(), Monster::getPower() and Monster::getGold() return? If not references, then change those also. That's all for now.