• Advertisement
Sign in to follow this  

Namespaces are my latest headache

This topic is 3389 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
string.h is obsolete and doesn't make use of namespaces, just #include <string>;

EDIT: Oh, and 'using namespace' in a header file is probably bad practice.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement