Sign in to follow this  
Blednik

Namespaces are my latest headache

Recommended Posts

Hey again. I'd like to know why my compiler fails to recognize the std namespace in the following two cases. Neither of the two examples will compile and both error out (see below). The code is in a header file that is #include-d inside another cpp file. Seems almost like as if the std namespace wasn't being defined in string.h, but I always thought string *was* a part of "std" namespace. I'm getting the same result in msvc++6 and msvc++9. Why is this so and more importantly what's the solution? I've figured that including some other things like <vector> will solve the problem, but that doesn't answer my question.
#ifndef SOME_HEADER
#define SOME_HEADER
#include <string.h>
using namespace std;
string asd;
#endif


#ifndef SOME_HEADER
#define SOME_HEADER
#include <string.h>
std::string asd;
#endif


Errors: d:\(path-to-file)\aaa.h(6) : error C2653: 'std' : is not a class or namespace name d:\(path-to-file)\aaa.h(6) : error C2146: syntax error : missing ';' before identifier 'asd' d:\(path-to-file)\aaa.h(6) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int d:\(path-to-file)\aaa.h(6) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int [Edited by - Blednik on October 10, 2008 2:00:04 PM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this