Advertisement
Guest User

Untitled

a guest
Sep 19th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. /*g++ -g -std=c++14 file.cpp -o file.exe
  2. * file.cpp:
  3. */
  4.  
  5. #include <stdio.h>
  6. #include <iostream>
  7. #include <string>
  8.  
  9. class b {
  10. public:
  11. b(const char *n) : n(n) {};
  12. operator const char *() const {
  13. return n;
  14. }
  15. const char *n;
  16. };
  17.  
  18. class a {
  19. public:
  20. a(const char *n) : n(n) {};
  21. operator b() const {
  22. return b(n);
  23. }
  24. const char *n;
  25. };
  26.  
  27. int main(int argc, char **argv) {
  28. a x("hello");
  29. b y = x;
  30. std::string z = (const char*)y;
  31. std::cout << y;
  32. std::cout << (b)x;
  33. //std::cout << x; would fail
  34. return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement