encapsulation

S

Simon Elliott

I have two classes A and B which encasulate some functionality. (In the
real example they are data access.)

xx.hpp:
class A
{
private:
class AImpl;
AImpl* pimpl_;
public:
A();
~A(void);
};

class B
{
private:
class BImpl;
BImpl* Bimpl_;
public:
B();
~B(void);
};

xx.cpp
class A::AImpl
{
public:
Tfoo fooA;
};

class B::BImpl
{
public:
Tfoo fooB;
};

Unfortunately in xx.cpp I now require A::AImpl to access B::fooB. But
B::pimpl_ is private (and I want to keep it that way). I don't want
xx.hpp to need to know anything about Tfoo as xx.cpp might one day be
re-written for Tbar.

Thoughts?
 
G

Gernot Frisch

Simon Elliott said:
I have two classes A and B which encasulate some functionality. (In
the
real example they are data access.)

xx.hpp:

class B;
class A
{
private:
class AImpl;
AImpl* pimpl_;

void AccessBfoo(cont B& pB);
public:
A();
~A(void);
};

class B
{
private:
class BImpl;
BImpl* Bimpl_;
public:
B();
~B(void);
};

xx.cpp
class A::AImpl
{
public:
Tfoo fooA;


void AccessBfoo(cont B& pB)
{
pB->fooB();
}
 

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,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top