code_junkie

C++ namespaces: cross-usage

Nov 13th, 2011
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. // a1.h
  2. #pragma once
  3. #include "a2.h"
  4.  
  5. namespace a1
  6. {
  7. const int x = 10;
  8. typedef a2::C B;
  9. }
  10.  
  11. // a2.h
  12. #pragma once
  13. #include "a1.h"
  14.  
  15. namespace a2 {
  16. class C {
  17. public:
  18. int say() {
  19. return a1::x;
  20. }
  21. };
  22. }
  23.  
  24. #include <iostream>
  25. #include "a1.h"
  26. #include "a2.h"
  27.  
  28. int main()
  29. {
  30. a2::C c;
  31. std::cout << c.say() << std::endl;
  32. }
  33.  
  34. #include "a2.h"
  35. #include "a1.h"
  36.  
  37. // a1.h
  38. #pragma once
  39.  
  40. namespace a2 {
  41. class C;
  42. }
  43.  
  44. namespace a1
  45. {
  46. const int x = 10;
  47. typedef a2::C B;
  48. }
Add Comment
Please, Sign In to add comment