Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. #ifndef CODE_HPP
  2. #define CODE_HPP
  3. #include <array>
  4. #include <vector>
  5. using std::vector;
  6. using std::array;
  7.  
  8. template<typename T, typename C = vector<T>>
  9. class stack;
  10.  
  11. template<typename T, typename C = vector<T>, typename K = stack<T,C>>
  12. class stack_array;
  13.  
  14. template<typename T, typename C>
  15. class stack
  16. {
  17. C pile;
  18.  
  19. stack();
  20. ~stack();
  21. void push(T&);
  22. friend class stack_array<T,C,stack<T,C>>;
  23. };
  24.  
  25.  
  26. template<typename T, typename C, typename K>
  27. class stack_array
  28. {
  29. private:
  30. static const size_t max_elem = 10;
  31. array<K, max_elem> store{};
  32. size_t index;
  33. public:
  34. stack_array(T&);
  35. ~stack_array();
  36. };
  37.  
  38.  
  39. template<typename T, typename C> stack<T,C>::stack(){
  40. pile.clear();
  41. }
  42.  
  43. template<typename T, typename C> stack<T,C>::~stack(){
  44. }
  45.  
  46. template<typename T, typename C> void stack<T,C>::push(T& _data){
  47. pile.push_back(_data);
  48.  
  49. return;
  50. }
  51.  
  52. template<typename T, typename C, typename K> stack_array<T,C,K>::stack_array(T& _data){
  53.  
  54. index = 0;
  55.  
  56. store[index].push(_data);
  57. }
  58.  
  59. template<typename T, typename C, typename K> stack_array<T,C,K>::~stack_array(){
  60. }
  61.  
  62. #endif
  63.  
  64. #include "code.hpp"
  65. #include <iostream>
  66. using std::cout;
  67.  
  68. int main (void){
  69.  
  70. auto i = 0;
  71. stack_array<decltype(i)> s_a(i);
  72.  
  73. return 0;
  74. }
  75.  
  76. g++ -ggdb -std=c++17 -Wall main.cpp code.hpp
  77.  
  78. In file included from main.cpp:1:0:
  79. code.hpp: In instantiation of ‘stack_array<T, C, K>::stack_array(T&) [with T = int; C = std::vector<int, std::allocator<int> >; K = stack<int, std::vector<int, std::allocator<int> > >]’:
  80. main.cpp:8:35: required from here
  81. code.hpp:52:86: error: use of deleted function ‘std::array<stack<int, std::vector<int, std::allocator<int> > >, 10>::~array()’
  82. template<typename T, typename C, typename K> stack_array<T,C,K>::stack_array(T& _data){
  83. ^
  84. In file included from code.hpp:3:0,
  85. from main.cpp:1:
  86. /usr/lib/gcc/x86_64-pc-cygwin/7.4.0/include/c++/array:94:12: note: ‘std::array<stack<int, std::vector<int, std::allocator<int> > >, 10>::~array()’ is implicitly deleted because the default definition would be ill-formed:
  87. struct array
  88. ^~~~~
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement