fork download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. class FoodOrder {
  6. public:
  7. FoodOrder(string foodType);
  8. static int GetNextId();
  9. private:
  10. string type = "None";
  11. int id = 0;
  12. static int nextId;
  13. };
  14.  
  15. FoodOrder::FoodOrder(string foodType) {
  16. type = foodType;
  17. id = nextId;
  18.  
  19. nextId += 1;
  20. }
  21.  
  22. int FoodOrder::GetNextId() {
  23. return nextId;
  24. }
  25.  
  26. int FoodOrder::nextId = 70;
  27.  
  28. int main() {
  29. FoodOrder order1("Hamburger");
  30. FoodOrder order2("Cake");
  31. FoodOrder order3("Toast");
  32.  
  33. cout << "Next ID: " << FoodOrder::GetNextId() << endl;
  34.  
  35. return 0;
  36. }
Success #stdin #stdout 0.01s 5276KB
stdin
Standard input is empty
stdout
Next ID: 73