fork download
  1. #include <iostream>
  2.  
  3. // foo.h
  4. namespace foo
  5. {
  6. extern int bar;
  7. }
  8.  
  9. //foo.cpp
  10. namespace foo
  11. {
  12. int bar = 42;
  13. }
  14.  
  15. int setBar(int x)
  16. {
  17. std::cout << "old foo::bar: " << foo::bar << std::endl;
  18. foo::bar = x;
  19. std::cout << "new foo::bar: " << foo::bar << std::endl;
  20. }
  21.  
  22. int main()
  23. {
  24. setBar(999);
  25. }
  26.  
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
old foo::bar: 42
new foo::bar: 999