//Menu.h
#ifndef H_MENU
#define H_MENU
#include <iostream>
#include <vector>
#include <string>
using namespaced std;
class SportsClothingMenu
{
private:
Menu sportsClothingMenu;
public:
SportsClothingMenu(){}
private:
void _populate(){
Menu soccerClothesMenu("soccer");
//...add soccor clothes to soccerClothesMenu
sportsClothingMenu.add( soccerClothesMenu );
}
};
#endif
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
//menulmp.cpp
#include "Menu.h"
usingnamespace std;
struct Menu
{
std::string name; //could be menu name or a item name
std::vector<Menu> subMenus;
Menu(const std::string& name, const std::vector<Menu> subMenus): name(name), subMenus(subMenus){}
void add(const Menu& m){ subMenus.push_back(m);
}
};
class SportsClothingMenu needs to see a declaration of struct Menu. Moving the struct into the header before the class should help.
As coded, with a Menu member, the compiler needs to know what the Menu structure contains so it can work out the overall structure of the SportsClothingMenu class. You can avoid this dependency by using a Menu pointer (with a forward declaration), but then you will have to new (and delete) the Menu. This would also require you to move the implementation of void _populate() to the cpp file.