Advertisement
Guest User

Untitled

a guest
Nov 27th, 2014
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. template<typename T>
  7. class Set
  8. {
  9. public:
  10. class Iterator;
  11. void add(T v);
  12. void remove(T v);
  13. Iterator begin();
  14. Iterator end();
  15.  
  16. private:
  17. vector<T> data;
  18. };
  19.  
  20. template <class T>
  21. Set<T> addstuff()
  22. {
  23. Set<T> a;
  24. a.add(1);
  25. a.add(2);
  26. a.add(3);
  27. a.add("a string");
  28.  
  29. return a;
  30. }
  31.  
  32. void main()
  33. {
  34. addstuff<Set>(); //<< Error here. If I use addstuff<int>(), it would run but
  35. //I can't add string to it. I am required to be able to add
  36. //different data types to this vector
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement