Hi friends

im trying to get my menu working but i just cant seem to get it working ... these are my 3 errors

9 " In file included from main.cpp"
47 " no matching function for call to `Menu::Menu(const char[7])' "
49 "std::string' has no member named 'add' "

This is my code

-------------------------------------------------------------

//main.cpp
 
#include <iostream>
#include <vector>
#include <string>
#include <fstream>
#include <cstdlib>
 
#include "Menu.h"

using namespace std;
 
int main(){
{
 
cout<<"Testing First"<<endl;
}
 

system("pause");
return 0;
}

------------------------------------------------------------------

----------------------------------------------------

//menu.h
 
#ifndef H_MENU
#define H_MENU
 
#include <iostream>
#include <vector>
#include <string>
#include <fstream>
#include <cstdlib>
 
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); 

}
};
 
class SportsClothingMenu
{
 
private:
 string sportsClothingMenu;

public:
 SportsClothingMenu(){}

private:
 void _populate(){

 Menu soccerClothesMenu("soccer");
 //...add soccor clothes to soccerClothesMenu
 
sportsClothingMenu.add(soccerClothesMenu);
 }

};
 
#endif

please help me

47 " no matching function for call to `Menu::Menu(const char[7])' "

This is caused by the line
Menu soccerClothesMenu("soccer");
The problem here is that you're calling a constructor to create a Menu object, but there is no such constructor. I see you have a constructor that takes a std::string and a std::vector of Menus, but I do not see one that accepts a const char[7].

49 "std::string' has no member named 'add' "

This is caused by the line
sportsClothingMenu.add(soccerClothesMenu);

sportsClothingMenu is an object of type std::string. These objects do not have a member function named add. If you're trying to use the function you wrote named add, you have fundamentally misunderstood how to use functions, I'm afraid.

Your function add would be used like this:

add(someMenuObject);

where someMenuObject is an object of type Menu. If you want to do something that adds a std::string to your Menu object, you'l have to write a function to do it.

oh thankyou!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.