fork download
  1. //but when i JUST put (DEFAULT_SIZE) in outline definition of the class
  2. //constructor i get this error:no appropriate default constructor available
  3.  
  4. #define DEFAULT_SIZE 10
  5. template<typename T>
  6. class stack {
  7. public:
  8. stack(int size);
  9. private:
  10. T *elements;
  11. int size;
  12. int count;
  13. };
  14.  
  15. template<typename T>
  16. stack<T>::stack(int s=DEFAULT_SIZE) {
  17. cout << "--constructor called\n";
  18. size = s;
  19. elements = new T[size];
  20. count = 0;
  21. }
  22.  
  23. //finally the main of the program:
  24.  
  25. int main() {
  26. stack<int> u;
  27. u.push(4);
  28. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:16:35: error: redeclaration of 'stack<T>::stack(int)' may not have default arguments [-fpermissive]
 stack<T>::stack(int s=DEFAULT_SIZE) {
                                   ^
prog.cpp: In constructor 'stack<T>::stack(int)':
prog.cpp:17:1: error: 'cout' was not declared in this scope
 cout << "--constructor called\n";
 ^
prog.cpp: In function 'int main()':
prog.cpp:27:3: error: 'class stack<int>' has no member named 'push'
 u.push(4);
   ^
stdout
Standard output is empty