Advertisement

Does Win32 hate namespaces?

Started by November 17, 2000 08:51 PM
6 comments, last by IO Fission 24 years, 1 month ago
So I''m writing a program with my own manespaces in Win32 GUI (VC++ 6.0), and it keeps complaining anytime I try to use something in my new namespace that the namespace doesn''t exist! I know that it does (I''ve checked the syntax multiple times) but it refuses to work. I also tried using the std namespace from the iostream library (like this: "using namespace std;") and it said that the std namespace doesn''t exist either! This doesn''t happen when I make console apps. Any ideas? IO_FissionSig();
Make sure you''re using the right set of headers and the latest service pack (SP4? I think that''s it...).

MSVC6 comes with two sets of C++ standard headers that are completely incompatible with each other, and both have their own problems. The less problematic is the more recent set. It''s the headers you include without the ".h".

MSVC does many things wrong with C++, but so far I''ve not had any problems with namespaces that I can recall.
Advertisement
Here''s what i read in Strostrup''s book ''bout namespaces and #includes

in real c++, all you have to do is include, say , instead of , and that will bring all of the functions etc in the stdlib header into the std namespace. however, to access any of these, you''d still either have to qualify them w/ std:: or bust out some using declarations/directives.

including the header, and using the .h simply brings the library into the global namespace.

well, that''s what i read from strostrup

that doesn''t really explain why vc is saying that the namespaces don''t exist!

dunno, just my heads up..
-- Succinct(Don't listen to me)
Perhaps VC++ is differant, but with Borland you have to say using namespace xyz. The header should do that for you though. Otherwise you have to fully qualify the name just as you would with conflicting names. I would assume any external names would have the namespace in it otherwise you would have link errors where there are name conflicts. A program such as InspectExe will show you the exported names in an exe or dll.
Keys to success: Ability, ambition and opportunity.
Me again.

Just to reiterate my point:
I don''t actually want the std namespace - I was just using that to see if it didn''t recognise standard library stuff as well as the stuff that I''m making. Library incompatibility should not be a problem since I''m trying to make my own new namespace. It just tells me that any namespace I try to use (compiling in Win32 App mode) doesn''t exist.


IO_FissionSig();
Is the namespace visible in the play your using it? If your declaring a function, you need to explicitly say that it''s in a namespace. i.e.

namespace xyz {
void foo();
}

instead of

void xyz::foo();
Advertisement
IO Fission, what are you talking about? Try posting a sample of your source code. At what point do you #include your headers, and at what point do you declare a namespace?

    // This should compile without problems.#include <windows.h>namespace MyNamespace{   class MyClass   {   public:      int nData;   };};INT WINAPI WinMain( HINSTANCE, HINSTANCE, LPSTR, INT ){   MyNamespace::MyClass fooObj;   return 0;}// This will cause errorsnamespace MyNamespace{#include <windows.h>   class MyClass   {   public:      int nData;   };   INT WINAPI WinMain( HINSTANCE,HINSTANCE,LPSTR,INT)   {      MyNamespace::MyClass fooObj;   }};  




Edited by - Marsupial Rodentia on November 18, 2000 7:10:44 PM
OK, OK. Thanx to all - I found the problem:
Precompiled headers.

In the main.cpp file I had
#include "newnames.h"
#include
#include "StdAfx.h"

So I put the #include "StdAfx.h" first, before the others, and whadya know, different errors! Fixed it all up, and namespaces work now. Wierd precompiled header stuff.


IO_FissionSig();

This topic is closed to new replies.

Advertisement