fork download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. class A{
  5. public:
  6. operator std::string(){
  7. return "My string";
  8. }
  9. operator int(){
  10. return 55;
  11. }
  12. };
  13.  
  14.  
  15. int main(){
  16. A a;
  17. std::cout<<(int)a<<std::endl;
  18. std::cout<<(std::string)a<<std::endl;
  19. }
Success #stdin #stdout 0s 3028KB
stdin
Standard input is empty
stdout
55
My string