|
-
January 21st, 2003, 01:07 PM
#1
order of "using" and #includes
Hi,
can someone explain why the order of using statements and #includes makes a difference?
At first I had at the top of my file:
using namespace std
#include<iostreams.h>
#include<string.h>
and this didn't work but then I found out that I had to put the using statement after the #includes.
Why is this? is the "std" defined within one of those include files?
-
January 21st, 2003, 01:22 PM
#2
No, std is not defined within those header files. It is defined within <iostream> and <string> though.
You'll be having other major problems by trying to mix <iostream.h> and <string.h> with the STL. (I am assuming that is what you are doing b/c you want to use the std namespace.)
OK, now for you answer:
The problem with specifying "using" before "#include" is that many any function call (from templates or inline functions) inside the header file will now assume it is being called from the std namespace (that is if there is no namespace specifier before the call). The <iostream.h> and <string.h> header files were written *before* the concept of namespaces and thus assume no namespaces. That is why the compileer chokes, b/c it is looking in the wrong namespace for functions.
So, yes, the general rule of thumb is to only use "using" after you have included all your header files.
Hope this helps!
- Kevin
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|