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. Pointer to Doc class of SDI

Pointer to Doc class of SDI

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++
4 Posts 4 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.
  • O Offline
    O Offline
    Oliver123
    wrote on last edited by
    #1

    I have an SDI and want to get a pointer to class SDIDoc. If I was creating a new class instance from within SDIDoc, I would do the following: SomeClass* pSC = new SomeClass; Then I would have a pointer pSC to the new instance of SomeClass. But, since SDIDoc already exists, and I am within SDIDoc, how do I get a pointer to SDIDoc? In SDIDoc.h I have the following: SDIDoc* pSDIDoc; In SDIDoc.cpp, I am looking for the following: pSDIDOC = ??????? Thanks

    D B N 3 Replies Last reply
    0
    • O Oliver123

      I have an SDI and want to get a pointer to class SDIDoc. If I was creating a new class instance from within SDIDoc, I would do the following: SomeClass* pSC = new SomeClass; Then I would have a pointer pSC to the new instance of SomeClass. But, since SDIDoc already exists, and I am within SDIDoc, how do I get a pointer to SDIDoc? In SDIDoc.h I have the following: SDIDoc* pSDIDoc; In SDIDoc.cpp, I am looking for the following: pSDIDOC = ??????? Thanks

      D Offline
      D Offline
      dtr1
      wrote on last edited by
      #2

      pSDIDoc=this; (or I don’t understand the question :confused:)

      1 Reply Last reply
      0
      • O Oliver123

        I have an SDI and want to get a pointer to class SDIDoc. If I was creating a new class instance from within SDIDoc, I would do the following: SomeClass* pSC = new SomeClass; Then I would have a pointer pSC to the new instance of SomeClass. But, since SDIDoc already exists, and I am within SDIDoc, how do I get a pointer to SDIDoc? In SDIDoc.h I have the following: SDIDoc* pSDIDoc; In SDIDoc.cpp, I am looking for the following: pSDIDOC = ??????? Thanks

        B Offline
        B Offline
        bob16972
        wrote on last edited by
        #3

        From MSDN, All nonstatic member functions can use the this keyword, which is a const (nonmodifiable) pointer to the object for which the function was called. ... Occasionally, the this pointer is used directly — for example, to manipulate self-referential data structures, where the address of the current object is required.

        1 Reply Last reply
        0
        • O Oliver123

          I have an SDI and want to get a pointer to class SDIDoc. If I was creating a new class instance from within SDIDoc, I would do the following: SomeClass* pSC = new SomeClass; Then I would have a pointer pSC to the new instance of SomeClass. But, since SDIDoc already exists, and I am within SDIDoc, how do I get a pointer to SDIDoc? In SDIDoc.h I have the following: SDIDoc* pSDIDoc; In SDIDoc.cpp, I am looking for the following: pSDIDOC = ??????? Thanks

          N Offline
          N Offline
          Nelek
          wrote on last edited by
          #4

          Hi, I did it within the stdafx.cpp, the #include MyDocument.h should be in stdafx to do this

          CMyDoc* pMyDoc;

          In your CMyView::OnInitialUpdate () just make

          extern CMyDoc* pMyDoc;
          pMyDoc = GetDocument ();
          ASSERT (pMyDoc);

          if it is made correctly, you have Doc access from every class using it. I.E.

          class CMyObject : public CObject
          {
          public:
          void MyMethode ();
          }

          void CMyObject::MyMethode ()
          {
          extern CMyDoc* pMyDoc;

          any_local_variable = pMyDoc->a_document_variable;
          return;
          }

          Greetings. -------- M.D.V. If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you “The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson ;)

          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