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. How to access object of a class declared in one file from another file?

How to access object of a class declared in one file from another file?

Scheduled Pinned Locked Moved C / C++ / MFC
c++tutorialquestion
5 Posts 3 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.
  • A Offline
    A Offline
    Amarelia
    wrote on last edited by
    #1

    Hi Friends I have developed an application(MFC based ) in which first I have my object of one class say objMyClass in one file called File1.h and I have used it in File1.cpp. NOw I want to used the same object(I don't want to create new object) in my another file say File2.h and File2.cpp....how to do that ? Any clue ? Thankx a lot Mahesh

    O 1 Reply Last reply
    0
    • A Amarelia

      Hi Friends I have developed an application(MFC based ) in which first I have my object of one class say objMyClass in one file called File1.h and I have used it in File1.cpp. NOw I want to used the same object(I don't want to create new object) in my another file say File2.h and File2.cpp....how to do that ? Any clue ? Thankx a lot Mahesh

      O Offline
      O Offline
      Owner drawn
      wrote on last edited by
      #2

      Use extern

      Jesus Loves

      --Owner Drawn --Nothing special --Defeat is temporary but surrender is permanent --Never say quits --Jesus is Lord

      A 1 Reply Last reply
      0
      • O Owner drawn

        Use extern

        Jesus Loves

        --Owner Drawn --Nothing special --Defeat is temporary but surrender is permanent --Never say quits --Jesus is Lord

        A Offline
        A Offline
        Amarelia
        wrote on last edited by
        #3

        Is it possible to use extern for Objects also. I know we can use it for variables but not sure for object. Also what I want mainly is I don't want to create new objects I just want to use that same object in it's present state. And last but not the least, Thankx a lot for answering my question and taking time for it. Regards Mahesh

        O S 2 Replies Last reply
        0
        • A Amarelia

          Is it possible to use extern for Objects also. I know we can use it for variables but not sure for object. Also what I want mainly is I don't want to create new objects I just want to use that same object in it's present state. And last but not the least, Thankx a lot for answering my question and taking time for it. Regards Mahesh

          O Offline
          O Offline
          Owner drawn
          wrote on last edited by
          #4

          Yeah mahesh extern can be used on objects too.

          Jesus Loves

          --Owner Drawn --Nothing special --Defeat is temporary but surrender is permanent --Never say quits --Jesus is Lord

          1 Reply Last reply
          0
          • A Amarelia

            Is it possible to use extern for Objects also. I know we can use it for variables but not sure for object. Also what I want mainly is I don't want to create new objects I just want to use that same object in it's present state. And last but not the least, Thankx a lot for answering my question and taking time for it. Regards Mahesh

            S Offline
            S Offline
            sunit5
            wrote on last edited by
            #5

            even u can extern with function.As function r global by default unless u have not put static with function declaration never say die

            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