![]() |
Using the Standard Template Library With OCF/OWL Classes.The standard template library(STL) contains some classes which conflict with classes found elsewhere in the Borland Libraries. Specifically the STL classes use a different exception handling base class, so catch(xmsg&){} will not catch STL exceptions. More of a problem, the STL uses its own string class which conflicts with that found in cstring.h. This means that if you #include any header file that depends upon cstring.h (any OWL or OCF header) then you will not normally be able to use the STL. Workaround: Before any #include of an STL header add the line: #define string _string After any #include of an STL header file add the line: #undef string This works by renaming the class string in the STL headers as _string. This is only permitted because the STL code is all templatised, and is therefore contained in the header files and recompiled for each project. You will probably want to add the line: using namespace std; to make the STL classes visible to your code module. For example: #include <owl/pch.h> #define string _string #include <string> #undef string using namespace std; string AString; //creates an instance of ::string (in cstring.h) _string AnotherString; //creates an instance of std::_string (in string.h) ......//etc.
Copyright Dr J. Maddock. Last Updated: 22 Dec 1996 |