// IN Mapping.h #include #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) { ourMap[this] = NV(name,value); } void SetName(string name) { ourMap[this].first = name; } string GetName(void) { return ourMap[this].first; } void SetValue(int value) { ourMap[this].second = value; } int GetValue(void) { return ourMap[this].second; } typedef pair NV; static map > ourMap; }; map > MappingImpl::ourMap; 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(); }