fork(1) download
  1. #include <iostream>
  2.  
  3. namespace CHECK // namespace to let "operator ==" not become global
  4. {
  5. typedef char no[7];
  6. template<typename T> no& operator == (const T&, const T&);
  7.  
  8. template <typename T>
  9. struct opEqualExists // *(T*)(0) can be replaced by *new T[1] also
  10. {
  11. enum { value = (sizeof(*(T*)(0) == *(T*)(0)) != sizeof(no)) };
  12. };
  13. }
  14.  
  15. #pragma pack(1)
  16. struct A
  17. {
  18. int x;
  19. short y;
  20. char z;
  21.  
  22. A& operator == (A const &);
  23. };
  24. #pragma pack()
  25.  
  26. int main() {
  27. std::cout << "sizeof(A) = " << sizeof(A) << std::endl;
  28. std::cout<< "operator ==() : exists? " << CHECK::opEqualExists<A>::value<<std::endl;
  29. }
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
sizeof(A) = 7
operator ==() :  exists?  0