This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: gcc/g++ 3.0.3 namespace problem


On Wed, Feb 13, 2002 at 10:48:11AM -0600, Ukrit Visitkitjakarn wrote:
> Dear all,
> 
> First, I'd like to thank John and Kayvan for helping me fix the problem in my
> cpp code, which was caused by improper use of namespace.
> 
> The test code that I used is listed below for reference.
> 
> test.cpp:
> #include <string>
> #include <stdio.h>
> int main() {
>   string a;
>   a="test";
>   printf ( "test message: %s", a.c_str());
>   return 0;
> }
> 
> John and Kayvan suggested using 'using namespace std;' to make this test code
> compiled.  I tested it and it works.  

I actually suggested adding "using std::string;"

The point of namespaces is to reduce the symbol pollution that can
result in name collisions. So, if you are going to use namespaces, my
inclination is to import only the symbols your program uses (rather
than the sledgehammer approach of "using namespace std;")

> Now I ran into the problem where I have almost 50 files to change (inserting
> 'using namespace std;'.)  

Again, my inclination would be to try and compile each file and add
the right "using" statements to each that would make it compile.
In the strictest sense, your source code is non-compliant with the
standard.

> Is there any gcc/g++ switch/flag that I can use so that I can compile the test
> code without using 'using namespace std;' ?   

You could try the -fpermissive flag and see if it works.

I'd just make the changes, though.

Best regards,

			---Kayvan

[[ Available for consulting. http://www.sylvan.com/~kayvan/Resume.html ]]
-- 
Kayvan A. Sylvan          | Proud husband of       | Father to my kids:
Sylvan Associates, Inc.   | Laura Isabella Sylvan  | Katherine Yelena (8/8/89)
http://sylvan.com/~kayvan | "crown of her husband" | Robin Gregory (2/28/92)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]