Override public virtual Functions with private Functions?

D

Daniel Pitts

Chris said:
Daniel said:
Chris 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
If you want to "hide" the implementation classes from client code, put
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
Using the anonymous namespace approach requires that anything using the
"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.
 

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

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top