Hello all, I've got a beginner question about object orientation in c++...
Let's say I have two interfaces, foo.h and bar.h
1 2 3 4 5
|
class foo
{
public:
virtual void DoStuff( ) = 0;
}
|
1 2 3 4 5
|
class bar
{
public:
virtual void DoThings( ) = 0;
}
|
And let's say I have one class implementing both of these interfaces
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
class FooBarImpl : public foo, public bar
{
private:
int m_dwFooStuff;
int m_dwBarThings;
public:
// Foo Methods
void DoStuff( );
// Bar Methods
void DoThings( );
private:
// Helper Methods
void CalculateSomeStuff( );
}
|
Okay, so here's what I want to do. I want the variable
m_dwBarThings
to ONLY be accessible by methods that were inherited from bar.h. So therefore it is in scope for
DoThings( )
but
DoStuff( )
does not have access to it, neither do any other non-interface methods like
CalculateSomeStuff( )
I know I can just write the code so those methods don't access that member variable lol. I want to prevent future developers from accidentally using that variable somewhere else in the class.
Let's also say that this class can be used/accessed by multiple threads (if that matters to you guys).
Here's my best guess, you guys will suggest that I put
m_dwBarThings
into bar.h as a protected member variable, then FooBarImpl gets it for free.