Menu linking Compilie error :(

Hi im trying to get this to compile im try to make a menu this is my code but it wont work

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//main.cpp

#include <iostream>
#include "Menu.h"
  
using namespace std;

int main(){
{
    SportsClothingMenu();
}
 
system("pause");
return 0;
}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
//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"

using namespace 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); 
    
   }
};


please somebody help me iv tryed everything
i get this error

" In file included from main.cpp " problem with #include "Menu.h"
you must define an object in the main.cpp


SportsClothingMenu mySport ();
Last edited on
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.
Last edited on
ok do you see this code nessary as i need to create a menu for a catalouge


Catalouge"
1.Shoes
2.Shirts
3.Adds a catagory
4.Adds a selling item
5.Quit

and i need to store the items into a binary tree

Topic archived. No new replies allowed.