fork download
  1. #include <string>
  2. #include <functional>
  3. #include <unordered_set>
  4.  
  5. template<typename T> class BaseB {
  6.  
  7. protected:
  8. std::string ms;
  9.  
  10. private:
  11. struct hashstruct {
  12. std::size_t operator()(const T & b) const {
  13. return b.hash();
  14. }
  15. };
  16.  
  17. public:
  18. bool operator==(const T & b) const {
  19. return ms == b.ms;
  20. }
  21.  
  22. virtual std::size_t hash() const = 0;
  23.  
  24. typedef std::unordered_set<T, hashstruct> Set;
  25. };
  26.  
  27. class B01 : public BaseB<B01> {
  28.  
  29. public:
  30. std::size_t hash() const {
  31. return std::hash<std::string>{}(ms) ^ 1;
  32. }
  33. };
  34.  
  35. class B02 : public BaseB<B02> {
  36.  
  37. public:
  38. std::size_t hash() const {
  39. return std::hash<std::string>{}(ms) ^ 2;
  40. }
  41. };
  42. class B03 : public B01 , public B02, public BaseB<B03>{
  43.  
  44. public:
  45. std::size_t hash() const {
  46. return 0;
  47. }
  48. };
  49.  
  50. int main(int iArgs, char * args[]) {
  51.  
  52. B01::Set setOfB01;
  53. setOfB01.insert(B01());
  54.  
  55. B02::Set setOfB02;
  56. setOfB02.insert(B02());
  57.  
  58. B03::Set setOfB03;
  59. setOfB03.insert(B03());
  60.  
  61. return 0;
  62. };
Compilation error #stdin compilation error #stdout 0s 3468KB
stdin
Standard input is empty
compilation info
prog.cpp: In function 'int main(int, char**)':
prog.cpp:58:5: error: reference to 'Set' is ambiguous
     B03::Set setOfB03;
     ^
prog.cpp:24:51: note: candidates are: typedef class std::unordered_set<B03, BaseB<B03>::hashstruct, std::equal_to<B03>, std::allocator<B03> > BaseB<B03>::Set
         typedef std::unordered_set<T, hashstruct> Set;
                                                   ^
prog.cpp:24:51: note:                 typedef class std::unordered_set<B02, BaseB<B02>::hashstruct, std::equal_to<B02>, std::allocator<B02> > BaseB<B02>::Set
prog.cpp:24:51: note:                 typedef class std::unordered_set<B01, BaseB<B01>::hashstruct, std::equal_to<B01>, std::allocator<B01> > BaseB<B01>::Set
prog.cpp:59:5: error: 'setOfB03' was not declared in this scope
     setOfB03.insert(B03());
     ^
stdout
Standard output is empty