Topic: Virtual Class w/data


Author: olavi@zow.desy.de (Olaf Manczak)
Date: 1995/07/25
Raw View
I need an advice how to deal with the followin problem -
what I would like to have is the following design of the class hierarchy:

class A
{
protected:
 int data;
public:
 virtual int method(const A&) = 0;
};

class B : public A
{
public:
 int method(const A& a) { use a.data; } // just a two argument method
};

It doesn't work because B can access data only as a member of class B and to
make it visible and accesible as a member of class A one should replace
`protected' with `public'. But what I need is to keep data as sth non-public
and visible among all the classes derived from A. Any hints ?

-- Olaf Manczak