I have a The problem in setting it up globally is that all my donuts are being eaten "eaten" will be marked, And if it's local Programmed it will not disappear when eaten. Take a boolean for a donut. If you have donut squares, add member flag: Or maybe you do not want to store information in the donut, so you can do a mapping;) But then you will need to implement the operator & lt; For donut :) Or, if you know that you have 10 donuts then you can have a stable array to hold dots eating flags: Or, if you do not know the number of donuts Use dynamic container at compile time: Still, the question has been edited, so we're sure That's you donut class. So here it goes: I'm very kind today;) < / Html> donut class, with a
eaten boolean field . I need to make the boolean a global variable to work, but it needs to be local, so I can make many
donut examples, where there is something "eaten" and nothing else I want to I am happy that the sweet disappears graphically when it has been eaten
square donut {bool m_bEaten; };
std :: map & lt; Donut, bool & gt; Donuts;
< Code> bool eatenDoughnuts [10]; // Start properly // Any donut you like: eaten donuts [2] = true; // Check that you have eaten donut number 2: if (Khaya donuts [2]) {// pure donut number 2.}
std :: vector & lt; Bool & gt; AtenDoughnuts; Or, use template meta-programming to eat at the time of donating your donuts;)
#include & lt; Vector & gt; Square donut {public: enum type (vanilla, chocolate); // Like your donut donut (type = vanilla) // vanilla is the default: the way (k), eaten (false) {} zero eat () {eaten = true; } // We eat Donuts Bull Eaton () {eaten back; Private: Like the way; // eat like your donut; // Has anyone eaten it yet? }; Int main () {// Your Delicious Donuts Package :) std :: vector & lt; Donut & gt; DeliciousDoughnuts; // Buy some delicious donuts. DeliciousDoughnuts.push_back (donut :: vanilla); DeliciousDoughnuts.push_back (donut :: chocolate); DeliciousDoughnuts.push_back (donut :: vanilla); // Do you love delicious chocolate donuts? eat it! DeliciousDoughnuts [1] .eat (); // Check you have put it down or you are good! If (tasty donnuts [1] .isEaten ()) {// poor chocolate donut ...}}
Comments
Post a Comment