Advertisement
Guest User

Untitled

a guest
Feb 28th, 2015
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. template <class First, class Second>
  2. struct compressed_pair : First, Second
  3. {
  4. compressed_pair() {}
  5. compressed_pair(const First& x, const Second & y)
  6. : First(x), Second(y)
  7. {}
  8. First& first() { return *this; }
  9. Second& second() { return *this; }
  10. };
  11.  
  12. struct a
  13. {};
  14.  
  15. struct b : a
  16. {};
  17.  
  18. int main()
  19. {
  20. compressed_pair<a, b> p;
  21. auto x = p.first();
  22. }
  23.  
  24. compressed_pair.cpp:8:30: error: ambiguous conversion from derived class 'compressed_pair<a, b>' to base class 'a':
  25. struct compressed_pair<struct a, struct b> -> struct a
  26. struct compressed_pair<struct a, struct b> -> struct b -> struct a
  27. First& first() { return *this; }
  28. ^~~~~
  29. compressed_pair.cpp:21:16: note: in instantiation of member function 'compressed_pair<a, b>::first' requested here
  30. auto x = p.first();
  31. ^
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement