code_junkie

Best practices for use of C++ header files

Nov 13th, 2011
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. /* Copyright Note and licence information (multiple lines) */
  2. #ifndef FOO_H
  3. #define FOO_H
  4. // Header file contents
  5. #endif
  6.  
  7. #ifndef FOO_H
  8. #define FOO_H
  9. namespace FooNameSpace{
  10. // Header file contents
  11. }
  12. #endif
  13.  
  14. #ifndef FOO_H
  15. #define FOO_H
  16. namespace AnotherNameSpace{
  17. class AnotherFoo; // forward declaration
  18. }
  19.  
  20. namespace FooNameSpace{
  21. // Use AnotherFoo here
  22. }
  23. #endif
  24.  
  25. // WRONG!
  26. using namespace std;
  27. class MyClass
  28. {
  29. string stringVar;
  30. };
  31.  
  32. // RIGHT
  33. class MyClass
  34. {
  35. std::string stringVar;
  36. };
Add Comment
Please, Sign In to add comment