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. Include headers.

Include headers.

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestion
5 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.
  • N Offline
    N Offline
    Neha
    wrote on last edited by
    #1

    Hi I have a header file x.h in this I have #include "y.h" In y.h file I want to use the class declared in x.h. But if I include x.h in y.h file, it is giving me an error saying class X is not decalred. Could anyone tell me how to solve this? Regards Neha

    P 1 Reply Last reply
    0
    • N Neha

      Hi I have a header file x.h in this I have #include "y.h" In y.h file I want to use the class declared in x.h. But if I include x.h in y.h file, it is giving me an error saying class X is not decalred. Could anyone tell me how to solve this? Regards Neha

      P Offline
      P Offline
      Prakash Nadar
      wrote on last edited by
      #2

      :wtf: :wtf: x , y , y , x , ... *uggg* put this line where you using it. class X;


      MSN Messenger. prakashnadar@msn.com Tip of the day of visual C++ IDE. "We use it before you do! Visual C++ was developed using Visual C++"

      N 1 Reply Last reply
      0
      • P Prakash Nadar

        :wtf: :wtf: x , y , y , x , ... *uggg* put this line where you using it. class X;


        MSN Messenger. prakashnadar@msn.com Tip of the day of visual C++ IDE. "We use it before you do! Visual C++ was developed using Visual C++"

        N Offline
        N Offline
        Neha
        wrote on last edited by
        #3

        Thanks for the reply. Here is the code In X.h #include "y.h" Class X { } In Y.h #include "X.h" Class X; Class Y { X m_Item; } In this case I will get a error as 'm_Item' uses undefined class 'X' How to slove this?

        C 2 2 Replies Last reply
        0
        • N Neha

          Thanks for the reply. Here is the code In X.h #include "y.h" Class X { } In Y.h #include "X.h" Class X; Class Y { X m_Item; } In this case I will get a error as 'm_Item' uses undefined class 'X' How to slove this?

          C Offline
          C Offline
          Cedric Moonen
          wrote on last edited by
          #4

          Instead of using the class X, use a pointer to the class: Class Y { X* m_Item; } This will solve your problem because you won't have to include the X.h header in the Y.h file (you'll have to include it in the Y.cpp file instead). Hope this helps

          1 Reply Last reply
          0
          • N Neha

            Thanks for the reply. Here is the code In X.h #include "y.h" Class X { } In Y.h #include "X.h" Class X; Class Y { X m_Item; } In this case I will get a error as 'm_Item' uses undefined class 'X' How to slove this?

            2 Offline
            2 Offline
            224917
            wrote on last edited by
            #5

            Just remove line #include "y.h" from X.h file it should work


            greatest thing is to do wot others think you cant
            suhredayan@omniquad.com>

            messenger :suhredayan@hotmail.com

            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