fork download
  1. #include <iostream>
  2.  
  3. class Stack
  4. {
  5. int* m_head;
  6. int m_size;
  7. int m_index;
  8. public:
  9. Stack(int size) : m_size{ size }, m_index{ 0 } {
  10. m_head = new int[size];
  11. }
  12. ~Stack() {
  13. delete[] m_head;
  14. }
  15. bool push (int x)
  16. {
  17. if (m_index < m_size)
  18. {
  19. m_head[m_index++] = x;
  20. return true;
  21. }
  22. std::cout << "the stack is full" << std::endl;
  23. return false;
  24. }
  25. };
  26. int main()
  27. {
  28. int n = 5;
  29. Stack stack{n};
  30. for (int i = 0; i < n; i++) {
  31. if (!stack.push(i)) return;
  32. }
  33. }
  34.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:31:29: error: return-statement with no value, in function returning ‘int’ [-fpermissive]
         if (!stack.push(i)) return;
                             ^~~~~~
stdout
Standard output is empty