unnamed namespaces

A

Anthony

Hello,

I have been reading up on unnamed namespaces in the context of hiding
classes as mentionned by the GOF Facade pattern description. I was
hoping someone could shed some light on this.
I would like the following classes where Facade has access to Alpha
and Beta which are otherwise hidden.

class Alpha
{
Beta b;
// and methods which call b methods
};

class Beta
{
Alpha a;
// and methods which use a methods
};

class Facade
{
// various manipulations of Alpha and Beta objects
};

However I would like to be able to seperate these classes into
seperate files (as in the case of say a compiler with a facade, the
subsystem classes are numerous and large and keeping this in one file
would be crazy). Is this at all feasible with unnamed namespaces as
the GOF book describes? My major problem is the organisation of the
code in headers and source files. On this front I'm totally lost!

NB: Yes I know I could always do this with private constructors and
friend classes but I would like to see a namespace version in action.

Any help would be greatly appreciated.

Many Thanks

Anthony
 
J

John Carson

Anthony said:
Hello,

I have been reading up on unnamed namespaces in the context of hiding
classes as mentionned by the GOF Facade pattern description. I was
hoping someone could shed some light on this.
I would like the following classes where Facade has access to Alpha
and Beta which are otherwise hidden.

class Alpha
{
Beta b;
// and methods which call b methods
};

class Beta
{
Alpha a;
// and methods which use a methods
};

class Facade
{
// various manipulations of Alpha and Beta objects
};

However I would like to be able to seperate these classes into
seperate files (as in the case of say a compiler with a facade, the
subsystem classes are numerous and large and keeping this in one file
would be crazy). Is this at all feasible with unnamed namespaces as
the GOF book describes?


No, it is not feasible. Stroustrup TC++PL, p 177: "In particular, unnamed
namespaces in different translation units are different. As desired, there
is no way of naming a member of an unnamed namespace from another
translation unit."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top