因此,我正在用C ++编写一个函数,该函数是一个小型数据库,其中包含运动和饮食两个类。这两个类非常相似,基本上完全相同。无论如何,我正在尝试打印我的运动课的内容。但是,我收到一条错误消息,提示函数StoreDailyPlan未定义。这很有趣,因为这两个类都有自己的重载函数版本,并且Diet版本运行良好。
void Wrapper::storeWeeklyPlan(ofstream& outfile, list<DietPlan>& dietlist)
{
DietPlan Node;
list<DietPlan>::iterator it; //this is our iterator, a pointer to the nodes in our list.
for(it = dietlist.begin(); it != dietlist.end(); it++) // start it at beginning, watch until end, and iterate it.
{
Node = *it;
storeDailyPlan(Node, outfile);
} //Another error here
}
void storeWeeklyPlan(ofstream& outfile, list<ExercisePlan>& exerciselist)
{
ExercisePlan Node;
list<ExercisePlan>::iterator it;
for (it = exerciselist.begin(); it != exerciselist.end(); it++)
{
Node = *it;
storeDailyPlan(Node, outfile); //THIS IS THE ERROR LINE
}
}
void Wrapper::storeDailyPlan(DietPlan diet, ofstream& outfile)
{
outfile << diet;
}
void Wrapper::storeDailyPlan(ExercisePlan exercise, ofstream& outfile)
{
outfile << exercise;
}
上面是直接负责将信息打印到文件上的4个功能。下面是一些其他相关代码。
class Wrapper
{
public:
Wrapper();
~Wrapper();
void runApp();
private:
int displayMenu();
void doChoice(int choice, list<DietPlan>& dietList, list<ExercisePlan>& exerciselist);
void loadDailyPlan(DietPlan& diet, ifstream& infile);
void loadDailyPlan(ExercisePlan& exercise, ifstream& infile);
void loadWeeklyPlan(ifstream& infile, list<DietPlan>& dietlist);
void loadWeeklyPlan(ifstream& infile, list<ExercisePlan>& exerciselist);
void storeWeeklyPlan(ofstream& outfile, list<DietPlan>& dietlist);
void storeWeeklyPlan(ofstream& outfile, list<ExercisePlan>& exerciselist);
void storeDailyPlan(DietPlan diet, ofstream& outfile);
void storeDailyPlan(ExercisePlan exercise, ofstream& outfile);
list <DietPlan> dietlist; //doubly linked list of DietPlan nodes. This is where it lives.
list <ExercisePlan> exerciselist;
};
如果您想查看其他任何代码,请告诉我。就像我说的那样,重载功能的节食版本效果很好。
我得到的错误是标识符“ storeDailyPlan”未定义并且 'storeDailyPlan':找不到标识符
我正在使用Visual Studio 2015。
答案 0 :(得分:2)
您在Wrapper::
定义之前输了storeWeeklyPlan
。
答案 1 :(得分:1)
storeWeeklyPlan
的声明中有错字。
// Replace this
void storeWeeklyPlan(ofstream& outfile, list<ExercisePlan>& exerciselist)
// With this
void Wrapper::storeWeeklyPlan(ofstream& outfile, list<ExercisePlan>& exerciselist)