Data from Document in a Dialog
-
In my CMyDocument class I've created a private CObList of some objects. How can I easily get access to this data in a safe way in my View class and dialog, created form my View class? In D.Kruglinski's book there's an example in Chapter 16 but the document there returns a pointer to the private data. But in Deitel's book "C++: How to Program" (Chapter 6.15) the authors do not recommend to return a reference or a pointer to the private data as it destroys the class incapsulation. Could you give me some piece of advice on this point?
-
In my CMyDocument class I've created a private CObList of some objects. How can I easily get access to this data in a safe way in my View class and dialog, created form my View class? In D.Kruglinski's book there's an example in Chapter 16 but the document there returns a pointer to the private data. But in Deitel's book "C++: How to Program" (Chapter 6.15) the authors do not recommend to return a reference or a pointer to the private data as it destroys the class incapsulation. Could you give me some piece of advice on this point?
Add public member functions that set/get the private information. That way, you preserve the encapsulation. The member functions should not return pointers but copies of the objects, so that users of the class can not modify the objects without the class' knowledge. Gary R. Wheeler
-
Add public member functions that set/get the private information. That way, you preserve the encapsulation. The member functions should not return pointers but copies of the objects, so that users of the class can not modify the objects without the class' knowledge. Gary R. Wheeler