D
Daniel Pitts
Using the anonymous namespace approach requires that anything using theChris said:Daniel said:If you want to "hide" the implementation classes from client code, putChris said:On May 28, 6:13 pm, Chris Gordon-Smith <[email protected]>
wrote:
James Kanze wrote:
[...]
True enough. In the case of my Action_Requests however, I
don't want to use the derived class' interface. I always want
to call polymorphically through the base interface.
In that case, you probably also want a factory which returns the
actual instances, so that the client code doesn't even know that
the derived classes exist. (And of course, in that case,
whether the virtual functions are public or are private in the
derived class really doesn't matter, since the client code
doesn't have access to the derived class definition.)
Yes. I have something like this. I make objects of the derived class
by reading input from a file. Depending on the kind of 'request' in
the file. I make an object of the appropriate derived class. Once this
has been done, nothing in the client code that manipulates the objects
knows about the derived classes.
(Hope this posting gets through OK. I can't get onto my news server at
the moment and so have had to go onto Google groups.)
Chris Gordon-Smith
www.simsoup.info
them into a anonymous namespace. That way, they can't ever access the
symbols that represent them, and they can only ever have access to your
instance through base class pointers or references.
Interesting. I just tried that, but now unfortunately my program won't link
because my factory class can't see the derived class' constructor.
Chris Gordon-Smith
www.simsoup.info
"hidden" namespace are in the same compilation unit (same file basically)
so you have a factory.h file which declares your factory and base class,
and a factory.cc file which defines the factory, base, and hidden
concrete classes.