[ create a new paste ] login | about

Link: http://codepad.org/GoVy0AdG    [ raw code | output | fork ]

C++, pasted on Oct 19:
#include <typeinfo>

class Int
{
public:
   Int()
   {
   }
   Int(const int& f)
   {
      IntOb=f;
   }
   friend std::ostream& operator <<(std::ostream& os, const Int& Ob)
   {
      os<<Ob.IntOb;
      return os;
   }
   operator double ()
   {
      return static_cast<double>(IntOb);
   }
private:
   int IntOb;
};

int main()
{
    Int Ob(5);
    std::cout<<typeid(Ob).name()<<'\n';
    std::cout<<Ob<<'\n';
    double s=static_cast<double>(Ob);
    std::cout<<typeid(s).name()<<'\n';
    std::cout<<s<<'\n';
    return 0;
}


Output:
1
2
3
4
3Int
5
d
5


Create a new paste based on this one


Comments: