Posted to c++ by avl at Tue Aug 01 13:36:59 GMT 2017view raw

  1. namespace TAO {
  2. class Any ;
  3.  
  4. // at time of template definition, almost nothing is
  5. // known about "Any".
  6. template < typename > struct Some {
  7. static inline void any_insert(Any *p , unsigned x ) { ( * p ) <<= x ; }
  8. };
  9.  
  10. void operator<<= ( TAO::Any&,unsigned);
  11.  
  12. class Any {
  13. //friend void operator<<=(TAO::Any&,unsigned);
  14. private:
  15. void operator<<= (unsigned char);
  16. };
  17.  
  18. }
  19.  
  20. main () {
  21. TAO::Any *a = 0;
  22. // by the time the template is used, the compiler knows about "Any".
  23. // but ignores the void operator<<= ( TAO::Any&,unsigned);
  24. // so it tries to cast the unsigned to unsigned char and
  25. // fails, because that is private.
  26. TAO::Some<void>::any_insert(a, 42);
  27. }
  28.