Click to See Complete Forum and Search --> : Include and "using namespace"
_uj
June 28th, 2007, 01:39 PM
Should you avoid using "using namespace" in an extended type .h file?
In classic C++ you avoid "using" in .h files but what about extended types, like say ref classes, in C++/CLI?
The reason I'm asking is that it's annoying to have to qualify all names in the type declaration. "Using" would be kind of neat.
^Johnny2Bad
June 28th, 2007, 02:13 PM
Well I use using in .h files at times and haven't run into any problems. And I am talking about managed C++ .h generally ref class .h files.
Cheers,
Jonathan
_uj
July 2nd, 2007, 11:32 PM
Well I use using in .h files at times and haven't run into any problems. And I am talking about managed C++ .h generally ref class .h files.
I'm asking because in principle the reason why you avoid "using" in classic C++ header files also should be applicable in the CLI extension case. I thought maybe there was some factor which makes it less bad but nothing comes to my mind. "Using" opens up a namespace a user of the .h file may not want to have open so basically it reduces his options which isn't good of course.
The reason you haven't experienced any problems so far probably is because you only use "using" with standard namespaces and own namespaces you completely control. Well, I think I stick with the old ways for the time being.
^Johnny2Bad
July 4th, 2007, 09:39 AM
Yeah I see what your saying, if a situation should occur where I have 2 or more namespaces conflicting with each other I'll have bizzaro things happening.
You are correct in saying that I have only used them on namespaces provided by .NET and my own created namespaces. I wasn't even aware that namespaces could be an issue in Visual Studio, I'm pretty sure someone on here mentioned that Visual Studio 2003 ignores namespaces anyway, but when I was coding on that thing I was doing unmanaged code only.
Cheers,
Jonathan.
codeguru.com
Copyright WebMediaBrands Inc., All Rights Reserved.