#ifndef PHONEH #define PHONEH #include #include //for basic_string and basic_ostringstream #include using namespace std; class phone { //a telephone number unsigned long n; public: phone(unsigned long initial_n): n(initial_n) {} operator unsigned long() const {return n;} }; template > class phone_put: public locale::facet { public: static locale::id id; //declaration explicit phone_put(size_t r = 0): locale::facet(r) {} virtual basic_string to_str(const phone& p) const { basic_ostringstream ost; ost << static_cast(p); //cast calls line 12 return ost.str(); } }; template locale::id phone_put::id; //definition of static data member template basic_ostream& operator<<(basic_ostream& ost, const phone& p) { const locale& loc = ost.getloc(); if (has_facet >(loc)) { ost << use_facet >(loc).to_str(p); } else { ost << static_cast(p); //cast calls line 12 } return ost; } #endif