Ok, I see now. I think the general rule is "use vector unless you are sure you need one of the others".
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Here's my scenario concerning my friend class..
in FleetMenu.cpp
in ContractMenu.hCode:class FleetMenu { public: friend class ContractMenu; FleetMenu(); private: void Pause(); void Clrscr();
in ContractMenu.cppCode:class ContractMenu { public: ContractMenu(); void Run(); private: .... private: .... };
ProblemCode:void ContractMenu::Run() { Clrscr(); }
am new to friends...Code:: error C3861: 'Clrscr': identifier not found
You need to:
1. make Clrscr static [I presume it doesn't actually use any member content]
2. call FleetMenu::Clrscr().
By making to classes friends, you are not inheriting the behaviour, you are just letting the other class use the private member functions of the class.
However, I'm not convinced that is the best way to form a menu - perhaps something based on tables is a better suggestion.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Code:class FleetMenu { public: //friend class ContractMenu; FleetMenu(); private: static void Pause(); static void Clrscr();Code:void ContractMenu::Run() { FleetMenu::Clrscr(); } // error C2248: 'FleetMenu::Clrscr' : cannot access private member declared in class 'FleetMenu'
You STILL need to make it a friend if you want to use that solution, but you ALSO need to have it static.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
By the way, here's a post I made a while back with regards to creating a menu system - perhaps you can use it as a base:
http://cboard.cprogramming.com/showp...6&postcount=18
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
looks interesting, lets take for example the following
1. how do i use your function // addmenu(std::string s, char c, menufunc f)... Or how do i replace the code above! ?Code:case 1: AddNewCar(); Pause(); break; case 2: UpdateFleetFile(); Pause(); break; case 3: EditFleetContract(); Pause(); break; case 4: DeleteCar(); Pause(); break;
2. If i have two different menus, how do i use your code?
1. If you move the Pause() to somewhere inside each of those functions, then you can easily just make those functions the "f" parameter (you'd have to add some extra parameters which you may or may not want to ignore).
If you have two different menus, you just create two menu objects - you can even make hierarchical menus by creating a new menu in one of the functions you call as a result of a menu choice.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Surely you can generate borders around it if you like - just count the number of items in the linked list and the lenght of the strings. You will want to replace this:
and put it into a function that counts the items + lengths, draws the frame and prints the items within a box - it shouldn't take that much effort.Code:for(p = head; p; p = p->next) { p->item->print(); }
Yes, it's a linked list, which I call a table in the sense that it is data rather than code, but it's obviously not an array - you could probably replace the linked list stuff with a vector<> and push_back instead of linked list insertion.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Can't i just modify this function
Maybe something like..Code:void menuitem::print() { std::cout << choice << ": " << descr << std::endl; }
then by looping this somehow the hashes will from a border?Code:std::cout << " \t\t#" << choice << "." << descr << " #\n" << std::endl;
Well, print shows only one menuitem - you need some way to determine how long ALL of the menu items are [or decide beforehand that everything should fit in X characters].
Obviously, if you have a constant width for all menus, then (as discussed elsewhere), you could just modify print() to do the right thing. It is probably STILL a good idea to add a function "drawmenu" or some such.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.