class A
{
private:
std::vector< int > m_vCommon;
public:
A( void ){};
~A( void ){};
std::vector< int >* GetCommonVector Ptr( void )
{
return &m_vCommon;
};
};
Actually, this is not a good solution. Class A has broken encapsulation by returning a pointer to its private data member. That means the data member can be altered by functions that are not class A functions. That means there is no control of the contents of the database.
In effect this is a global variable parading as a member variable.
When you have common data, you need to ask whether the data can change independently from the class objects. If this is the case, the object should have a pointer (preferably a handle) to the data.
The data itself is managed by another object altogether.
-
class DataManager
-
{
-
private:
-
vector<int> theData;
-
public:
-
SetTemperature(int arg);
-
int GetMaxTemperature();
-
//etc...
-
};
-
Here the vector contains temperatures. The SetTemperature( ) can regulate what goes in the data be refusing input like 263634673 degrees. Merely exposing a pointer to the vector destroys this ability.
class B now has a pointer to a DataManager object. It is the DataManager that provides access to the data through its public interface.
You really want to avoid closely coupled classes since it is the path to monolithic code.