#include #include /* This is a quick file to demonstrate how implicit construction * and friend operators work. * If you have operator== as a member function, then this won't compile. * If you have the non-member "friend", though, it works! * * I guess this also demos preprocessor directives... * oops? */ //#define _POLY_FRIEND_ using namespace std; class poly { public: poly(int x): c(1) {c[0]=x;} #ifdef _POLY_FRIEND_ friend bool operator==(const poly&, const poly&); #else bool operator==(const poly& p) const { return c == p.c; } #endif private: vector c; }; #ifdef _POLY_FRIEND_ bool operator==(const poly& p, const poly& q) { return p.c == q.c; } #endif int main(int argc, char* argv[]) { poly p = 1; cout << (1 == p) << endl; }