Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // A.cpp
- #include "A.h"
- #include "boost/shared_ptr.hpp"
- #include <vector>
- class A {
- // ...
- };
- //a.h
- #ifndef _A_H_
- #define _A_H_
- //... code ...
- #endif
- // -----------------
- //b.h
- #ifndef _B_H_
- #define _B_H_
- #include a.h
- //... code ...
- #endif
- // -----------------
- //main.cpp Try 1
- #include "b.h" //<- okay! b includes a, then does b
- // -----------------
- //main.cpp Try 2
- #include "a.h" //<- includes a
- #include "b.h" //<- okay! b includes a, but skips redefining it, then does b
- // -----------------
- //main.cpp Try 3
- #include "b.h" //<- b includes a, then does b
- #include "a.h" //<- okay! a skips redefining itself!
- // -----------------
- //main.cpp Try 4
- #include "a.h" //<- fail! b is not included anywhere =(
- // A.h
- #pragma once
- // or the #ifndef trick
- #include "B.h"
- // A.cpp
- #include "A.h"
- // A.h
- #pragma once
- // or the #ifndef trick
- //#include "B.h"
- // A.cpp
- #include "B.h"
- #include "A.h"
- class B; // forward declaration
- class A
- {
- void doStuff(const B& b);
- };
- #include <A.h>
- #include <B.h>
- int main()
- {
- A a;
- B b;
- a.doStuff(b);
- }
Add Comment
Please, Sign In to add comment