fork download
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. template<class T>
  6. class test
  7. {
  8. public:
  9.  
  10. void addItem(T element){
  11. elements.push_back(element);
  12. }
  13. T getItem(int i){
  14. return elements[i];
  15. }
  16. vector<T> elements;
  17. };
  18.  
  19. int main()
  20. {
  21. char * cpt[]={"tab","tab2","tab3"};
  22. test<char*> test1;
  23. test1.addItem(cpt[1]);
  24. char * item=test1.getItem(0);
  25. //Segmentation fault
  26. // could it be done without specialisation class for char* ?
  27. item[0]='Z';
  28. cout<<item<<endl;
  29. for(auto v:test1.elements) cout<<v<<endl;
  30. return 0;
  31. }
  32.  
Runtime error #stdin #stdout 0s 3268KB
stdin
Standard input is empty
stdout
Standard output is empty