
Using both STL and MFC with Visual C++ 5.0
[Cut stuff re conflict between MFC's afx.h and STL headers.]
Quote:
>> I solved that problem with a pair of files used thusly:
[Cut new_unhack.h and new_rehack.h ]
Quote:
>Although I'd agree that the use of #define is not a good solution for what
>MFC is trying to do here, your solution is not needed. The only reason
>you're having problems is because you're putting your #include statements in
>the wrong position.
I have to disagree here. While investigating the problem, I
also discovered that reordering includes would "cure" it.
After considering that alternative, I chose my solution
because I wanted the MFC headers in a .PCH and was
unwilling to stuff every possible STL include into the same
.PCH just to cater to a hack that I consider bone-headed.
You might say the only reason I was having problems is
that I am too stubborn to let some little hack dictate how
common includes, PCH use, and subsequent includes
are going to be structured for my (our) whole project. I
cannot duck that charge. I admit it. My stubbornness
reflects what I view as a sound design principle, which
is to not allow solutions of little issues to leak out into a
realm where solutions of larger problems are impacted.
My solution contains the problem instead of distorting
how we solve what should be unrelated problems.
Quote:
>#include <afxres.h> // example of MFC header
>#include <string> // STD headers should also be in this block!!
>// MFC debug new technique
>#ifdef _DEBUG
>#define new DEBUG_NEW
>#undef THIS_FILE
>static char THIS_FILE[] = __FILE__;
>#endif
The problem is that the above hack is in afx.h .
Either afx.h gets left out of the precompiled
headers, or a bunch of STL files not usually
used have to go into the .PCH. Just to make
that a more interesting choice, the VC6
compiler starts croaking with complaints
about heap space and need for /Zm switch
when some of our larger (auto-generated)
files get compiled with MFC, most of STL,
and the truly common project headers. The
STL adds a lot to the .PCH's.
Quote:
>#include <list> // Must NOT include headers after the #define new!!!
>In the above example, #include <list> will give you the grieve you're
>complaining about, while #include <string> will not. If you really are sick
>of all of this, you can always just delete the #define new stuff, as it's
>sole purpose is to provide you with debugging facilities for detecting memroy
>leaks. It won't hurt the code any at all to remove this, it just means
>you'll need some other method to detect memory leaks.
I am really sick of keywords being #define'd. Someday,
possible in another lifetime, I will use an alternative
dynamic memory checking facility.
--Larry Brasfield
Above opinions may be mine alone.