// IN Mapping.h #include #include class Mapping { public: Mapping(string name, int value); ~Mapping(void); void SetName(string name); string GetName(void); void SetValue(int value); int GetValue(void); private: class MappingImpl* myImpl; }; // IN MAIN PROGRAM int main(void) { Mapping m1("two",1); Mapping m2("three",1); cout << m1.GetName() << ": " << m1.GetValue() << endl; cout << m2.GetName() << ": " << m2.GetValue() << endl; m1.SetName("one"); m2.SetValue(3); cout << m1.GetName() << ": " << m1.GetValue() << endl; cout << m2.GetName() << ": " << m2.GetValue() << endl; } // IN Mapping.C class MappingImpl { private: friend class Mapping; MappingImpl(string name, int value) : myName(name) , myValue(value) {} void SetName(string name) { myName = name; } string GetName(void) { return myName; } void SetValue(int value) { myValue = value; } int GetValue(void) { return myValue; } string myName; int myValue; }; Mapping::Mapping(string name, int value) : myImpl ( new MappingImpl(name,value) ) {} Mapping::~Mapping(void) { delete myImpl; } void Mapping::SetName(string name) { myImpl->SetName(name); } string Mapping::GetName(void) { return myImpl->GetName(); } void Mapping::SetValue(int value) { myImpl->SetValue(value); } int Mapping::GetValue(void) { return myImpl->GetValue(); }