fork(6) download
  1. #include <iostream>
  2. #include <typeinfo>
  3. using namespace std;
  4.  
  5. class Str
  6. {
  7. const char* _s;
  8.  
  9. public:
  10. Str( const char* s ) : _s{s} { }
  11. //operator std::string() const { return std::string{_s}; }
  12. operator const char*() const { return _s; }
  13. };
  14.  
  15. std::ostream& operator<<( std::ostream& os, const Str& S )
  16. {
  17. return os << static_cast<std::string>(S);
  18. }
  19.  
  20. using B = Str;
  21. using V = const char*;
  22.  
  23. bool test( B b, V v )
  24. {
  25. cout << typeid(B).name() << endl << typeid(V).name() << endl;
  26.  
  27. V b_as_V{static_cast<V>(b)};
  28.  
  29. return b_as_V == v;
  30. }
  31.  
  32. int main() {
  33. cout << ( test( Str("ABC"), "ABC" ) ? "PASS" : "FAIL" );
  34. return 0;
  35. }
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
3Str
PKc
PASS