-1

So I am writing a function in C++ that is a small database, containing two classes, exercise and diet. These two classes are very similar, basically exactly alike. Anyway I am trying to print the contents of my exercise class. However I am getting an error message that the function StoreDailyPlan is undefined. This is interesting because both classes have their own version of that overloaded function, and the diet version is working just fine.

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;
}

Above are the 4 functions directly responible for printing the information onto the file. Below is some other relevant code.

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;
};

Please let me know if you would like to see any other code. Like I said, the diet version of the overloaded function works just fine.

The Errors I get are identifier "storeDailyPlan" is undefined and 'storeDailyPlan': identifier not found

I am using Visual Studio 2015.

Ryan M
  • 23
  • 4
  • storeDailyPlan is declared private – Soulimane Mammar Mar 02 '19 at 07:16
  • 1
    Please *indent* your code properly. It is unreadable as is. From the sound of it, you have accidentally defined `storeWeeklyPlan` as a global function, while you need `Wrapper::storeWeeklyPlan`. – n. m. could be an AI Mar 02 '19 at 07:20
  • Don't comment the obvious. Everybody (some minimal experience provided) knows what an iterator is and how a for loop works... – Aconcagua Mar 02 '19 at 07:29
  • To whoever closed this: it is **not** about the "undefined reference/unresolved external symbol" error. – n. m. could be an AI Mar 02 '19 at 08:13
  • Puh-lease. **THIS IS NOT ABOUT THE "UNDEFINED REFERENCE/UNRESOLVED EXTERNAL SYMBOL" ERROR**. I only have one reopen vote. Please reopen this. – n. m. could be an AI Mar 02 '19 at 12:05
  • Sorry about the dumb question fellas I'd spent 8 hours on this program and my mind was slipping. I see now that it's because of the fact that I didn't put Wrapper:: before the function. For whatever reason the compiler didn't catch that directly. – Ryan M Mar 02 '19 at 20:30
  • The compiler is not supposed to "catch this". You can legitimately have both `Wrapper::storeWeeklyPlan` and a global `storeWeeklyPlan` at the same time. These things are totally unrelated. – n. m. could be an AI Mar 03 '19 at 14:42

2 Answers2

2

You lost Wrapper:: before the definition of storeWeeklyPlan.

john
  • 85,011
  • 4
  • 57
  • 81
Yuanhui
  • 459
  • 5
  • 15
1

There's a typo in the declaration of storeWeeklyPlan.

// Replace this
void storeWeeklyPlan(ofstream& outfile, list<ExercisePlan>& exerciselist)
// With this
void Wrapper::storeWeeklyPlan(ofstream& outfile, list<ExercisePlan>& exerciselist)
Indiana Kernick
  • 5,041
  • 2
  • 20
  • 50