Skip to main content
GameDev.net gamedev.net
🔒 Locked

Does Win32 hate namespaces?

Started by IO Fission Nov 17, 2000 at 8:51 PM 6 replies 200+ views
Original Post
IO Fission
IO Fission
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();
Succinct
Succinct
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)
LilBudyWizer
LilBudyWizer
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.
IO Fission
IO Fission
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();
Wilka
Wilka
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();
Marsupial Rodentia
Marsupial Rodentia
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 errors

namespace 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
IO Fission
IO Fission
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();

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.