fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. const size = 50;
  5.  
  6. template <class T>
  7.  
  8. class arr
  9. {
  10. public:
  11. T a[size];
  12.  
  13. arr()
  14. {
  15. int i;
  16. for(i=0;i<size;i++)
  17. {
  18. a[i] = i;
  19. }
  20. }
  21. void put(T z , int i)
  22. {
  23. a[i] = z;
  24. }
  25. T get(int i)
  26. {
  27. return a[i];
  28. }
  29. };
  30.  
  31. int main()
  32. {
  33. arr<int> obj1;
  34. arr<float> obj2;
  35.  
  36. obj1.put(5,10);
  37. cout<<obj1.get(10)<<endl;
  38.  
  39. obj2.put(3.5 , 5);
  40. cout<<obj2.get(5)<<endl;
  41.  
  42. return 0;
  43. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:4:7: error: 'size' does not name a type
 const size = 50;
       ^
prog.cpp:11:6: error: 'size' was not declared in this scope
  T a[size];
      ^
prog.cpp: In constructor 'arr<T>::arr()':
prog.cpp:16:13: error: 'size' was not declared in this scope
   for(i=0;i<size;i++)
             ^
prog.cpp:18:4: error: 'a' was not declared in this scope
    a[i] = i;
    ^
prog.cpp: In member function 'void arr<T>::put(T, int)':
prog.cpp:23:3: error: 'a' was not declared in this scope
   a[i] = z;
   ^
prog.cpp: In member function 'T arr<T>::get(int)':
prog.cpp:27:10: error: 'a' was not declared in this scope
   return a[i];
          ^
stdout
Standard output is empty