我试图为作业创建一个地图,我在标题中声明了它,我试图访问它,但我不断收到错误。我不确定代码有什么问题。我在加载函数中实现了代码,但如果你能帮忙,我似乎无法让它在 get 函数中工作谢谢
这是头文件
class Movies {
// data is private by default
Movie *movies;
int movieCnt;
map<string,**string> Mymap;
public:
Movies(string);
int getMovieCount() const;
const Movie * getMovie(string) const;
~Movies();
private:
void loadMovies(string);
int getMovieHash(string) const;
};
这是代码
const Movie * Movies::getMovie(string mc) const {
if(mc.length()==0)
return NULL; // not found
else
return &(Mymap.find(mc));
}
Movies::~Movies() {delete[] movies; movies = NULL;}
void Movies::loadMovies(string fn) {
ifstream iS(fn); // technically should be c_str
string s;
getline(iS, s); // skip heading
getline(iS, s);
movieCnt=0;
while(!iS.eof()) {
Movie* m = new Movie(s);
Mymap[(m->getTitle())] = *m;
movieCnt++;
getline(iS, s);
}
iS.close();
}