Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Data from Document in a Dialog

Data from Document in a Dialog

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestionc++learning
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Space Ace
    wrote on last edited by
    #1

    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?

    G 1 Reply Last reply
    0
    • S Space Ace

      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?

      G Offline
      G Offline
      Gary R Wheeler
      wrote on last edited by
      #2

      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

      S 1 Reply Last reply
      0
      • G 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

        S Offline
        S Offline
        Space Ace
        wrote on last edited by
        #3

        Thanks for the tip, but how can I return a copy of a CObList object? Wouldn't it be too memory-consuming?

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups