Posted to c++ by avl at Tue Aug 01 13:36:59 GMT 2017view pretty
namespace TAO {
class Any ;
// at time of template definition, almost nothing is
// known about "Any".
template < typename > struct Some {
static inline void any_insert(Any *p , unsigned x ) { ( * p ) <<= x ; }
};
void operator<<= ( TAO::Any&,unsigned);
class Any {
//friend void operator<<=(TAO::Any&,unsigned);
private:
void operator<<= (unsigned char);
};
}
main () {
TAO::Any *a = 0;
// by the time the template is used, the compiler knows about "Any".
// but ignores the void operator<<= ( TAO::Any&,unsigned);
// so it tries to cast the unsigned to unsigned char and
// fails, because that is private.
TAO::Some<void>::any_insert(a, 42);
}