Discussion:
[omniORB] "using namespace" can't disambiguate generated types
Tom O'Reilly
2007-07-14 08:37:07 UTC
Permalink
I have been really struggling on this one.
I've defined a module in my IDL interface, generated C++ code with omniIDL, and for some reason am unable to take advantage of the C++ "using namespace" directive - thus I need to specify the actual namespace *everywhere* in my application code. Why the heck doesn't "using namespace" help disambiguate types in the generated classes?

Here is my simple IDL interface:

module oreillyTest {

interface ServerTest {

enum Status {
Ok, Failed
};

void ping();

short foo(out float x);

};
};

I compile the IDL to C++ with the following:

omniidl -bcxx -Wbh=.h -Wbs=_SK.cc ServerTest.idl


Now here is a simple implementation of the IDL interface:

#include "ServerTest.h"


class BasicServer : virtual public POA_test::ServerTest {

public:

BasicServer(oreillyTest::ServerTest::Status status);

virtual void ping();


oreillyTest::ServerTest::Status _status;

};


using namespace oreillyTest; // Don't want to use namespace everywhere

BasicServer::BasicServer(ServerTest::Status status) { // COMPILER ERROR HERE!!!
_status = status;
}



For some reason, gcc (v 4.0.0) cannot successfully compile this, giving:
BasicServer.cc:5: error: expected `)' before 'status'

I.e. I must prepend the namespace "oreillyTest::" before every occurrence of ServerTest::Status - even though I've specified "using namespace oreillyTest" - does anyone know why?

Thanks,
Tom


--------------------------------------------------
Thomas C. O'Reilly
Monterey Bay Aquarium Research Institute
7700 Sandholdt Road
Moss Landing, California 95039-9644
831-775-1766 (voice)
831-775-1620 (FAX)
***@mbari.org (email)
http://www.mbari.org (World-wide Web)

"The machine does not isolate man from the great mysteries
of nature, but plunges him more deeply into them."

- ANTOINE DE SAINT-EXUPERY
"Wind, Sand, and Stars" (1939)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.omniorb-support.com/pipermail/omniorb-list/attachments/20070713/6e744b36/attachment.htm
Duncan Grisby
2007-07-17 18:56:59 UTC
Permalink
Post by Tom O'Reilly
I've defined a module in my IDL interface, generated C++ code with
omniIDL, and for some reason am unable to take advantage of the C++
"using namespace" directive - thus I need to specify the actual
namespace *everywhere* in my application code. Why the heck doesn't
"using namespace" help disambiguate types in the generated classes?
[...]
Post by Tom O'Reilly
class BasicServer : virtual public POA_test::ServerTest {
I assume this is really POA_oreillyTest::ServerTest.

[...]
Post by Tom O'Reilly
using namespace oreillyTest; // Don't want to use namespace everywhere
BasicServer::BasicServer(ServerTest::Status status) { // COMPILER ERROR HERE!!!
_status = status;
I guess it has resolved ServerTest to be POA_oreillyTest::ServerTest
based on the inheritance, rather than using the namespace to find
oreillyTest::ServerTest. If you put the type definition of Status
outside the interface, I expect the namespace lookup will find it.

Cheers,

Duncan.
--
-- Duncan Grisby --
-- ***@grisby.org --
-- http://www.grisby.org --
Loading...