"#include" trouble
Here''s a silly question.
I''ve got two header files for two different classes, class A and class B. Both objects have pointers to types of the other class as private members. Here''s where my problem comes in...each class has to know about the other one. In the preprocessor directives for the header file "A.h" I have ''#include "B.h"''. For the "B.h" header file, I can''t have ''#include "A.h"'', or it would endlessly include each file over and over. What can be done to get around this? I hope I explained it clearly enough to understand my problem...if not just let me know.
Thanks in advance.
You make sure that each header file is only included once:
Note: The capitals are merely a naming convention, and are not mandatory.
If I have understood you correctly, you are also probably going to have to use a forward declaration. Have a look on Google to find out what I'm talking about.
[ Google || Start Here || ACCU || STL || Boost || MSDN || GotW || MSVC++ Library Fixes || BarrysWorld || E-Mail Me ]
[edited by - Lektrix on July 26, 2003 6:50:26 PM]
#ifndef FILE_NAME_OR_WHATEVER // if it hasn't been included
#define FILE_NAME_OR_WHATEVER // use this to show it's been included
class A
{
...
};
#endif
Note: The capitals are merely a naming convention, and are not mandatory.
If I have understood you correctly, you are also probably going to have to use a forward declaration. Have a look on Google to find out what I'm talking about.
[ Google || Start Here || ACCU || STL || Boost || MSDN || GotW || MSVC++ Library Fixes || BarrysWorld || E-Mail Me ]
[edited by - Lektrix on July 26, 2003 6:50:26 PM]
See the ''Header Files'' link in my signature.
[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]
[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]
OK then, don''t bother searching using Google, just have a look at the Fruny''s sig. link. :]
[ Google || Start Here || ACCU || STL || Boost || MSDN || GotW || MSVC++ Library Fixes || BarrysWorld || E-Mail Me ]
[ Google || Start Here || ACCU || STL || Boost || MSDN || GotW || MSVC++ Library Fixes || BarrysWorld || E-Mail Me ]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement