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. Extern and CLASS

Extern and CLASS

Scheduled Pinned Locked Moved C / C++ / MFC
question
5 Posts 5 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.
  • D Offline
    D Offline
    dannygilbert3
    wrote on last edited by
    #1

    Easy question but I don't find the answer.:sigh: I have a header file with some classes. These classes used some class from one another header file. How can I tell to compiler to use the classes from other header files ? Extern does not work, only work on object.

    Danny Gilbert Montréal, Canada

    M T J T 4 Replies Last reply
    0
    • D dannygilbert3

      Easy question but I don't find the answer.:sigh: I have a header file with some classes. These classes used some class from one another header file. How can I tell to compiler to use the classes from other header files ? Extern does not work, only work on object.

      Danny Gilbert Montréal, Canada

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      dannygilbert3 wrote:

      How can I tell to compiler to use the classes from other header files ?

      #include "OtherHeaderFile.h"

      1 Reply Last reply
      0
      • D dannygilbert3

        Easy question but I don't find the answer.:sigh: I have a header file with some classes. These classes used some class from one another header file. How can I tell to compiler to use the classes from other header files ? Extern does not work, only work on object.

        Danny Gilbert Montréal, Canada

        T Offline
        T Offline
        toxcct
        wrote on last edited by
        #3

        #include is the directive for you...


        You don't know where to start ? ask a good friend

        [VisualCalc 3.0][Flags Beginner's Guide]

        1 Reply Last reply
        0
        • D dannygilbert3

          Easy question but I don't find the answer.:sigh: I have a header file with some classes. These classes used some class from one another header file. How can I tell to compiler to use the classes from other header files ? Extern does not work, only work on object.

          Danny Gilbert Montréal, Canada

          J Offline
          J Offline
          James R Twine
          wrote on last edited by
          #4

          If you only need to declare pointers or references to those other classes, you can do a forward declaration (I believe that is what it is called) by putting code like this:

          class CClass;
               class CSomeOtherClass;

          Before the code that declare pointers/references to that class.

          class CClass;
          class CSomeOtherClass;

          class CMyClass
          {
             public:
             CMyClass( CClass *pClass );
             CMyClass( CSomeOtherClass &socSomeOtherClass );
             CMyClass( CAnotherClass *pAnotherClass );     // This One Will Not Compile
             CMyClass( CAnotherClass &cacAnotherClass );   // This One Will Not Compile
          };

          If you need to actually access members of the class, then you need to include the entire declaration of the class (usually by including its .H file).  This is usually required in the CPP file for the class that uses the other classes.  Be careful throwing includes around freely if you are not fully familiar with the code, you can introduce dependency problems and/or mess up your build times.    Peace!

          -=- James


          If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
          Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
          DeleteFXPFiles & CheckFavorites (Please rate this post!)

          1 Reply Last reply
          0
          • D dannygilbert3

            Easy question but I don't find the answer.:sigh: I have a header file with some classes. These classes used some class from one another header file. How can I tell to compiler to use the classes from other header files ? Extern does not work, only work on object.

            Danny Gilbert Montréal, Canada

            T Offline
            T Offline
            ThatsAlok
            wrote on last edited by
            #5

            http://www.codeproject.com/cpp/libfromdll.asp[^]

            "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

            cheers, Alok Gupta VC Forum Q&A :- I/ IV Support CRY- Child Relief and you

            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