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. Inclusion of header files

Inclusion of header files

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestion
13 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.
  • C CPallini

    Taruni wrote:

    I am trying to create an object of CMyClass in CMyDoc.h and for this purpose I have to include MyClass.h

    Possibly you're including MyClass.h in MyDoc.h and viceversa. you may use

    #pragma once

    at the top of you header files to prevent multiple inclusion. :)

    If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
    This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
    [My articles]

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

    Thank you Pallini. #program once is already there in all the header files except in MyClass.h.When I tried to include, I am getting the errors 'CMyClass' : is not a class or namespace name syntax error : identifier 'CMyClass' syntax error : missing ';' before '}' syntax error : missing ';' before '}' . . . . . fatal error C1003: error count exceeds 100; stopping compilation

    Taruni

    C 1 Reply Last reply
    0
    • T Taruni

      Thank you Pallini. #program once is already there in all the header files except in MyClass.h.When I tried to include, I am getting the errors 'CMyClass' : is not a class or namespace name syntax error : identifier 'CMyClass' syntax error : missing ';' before '}' syntax error : missing ';' before '}' . . . . . fatal error C1003: error count exceeds 100; stopping compilation

      Taruni

      C Offline
      C Offline
      CPallini
      wrote on last edited by
      #4

      What is the source file the error is given for? Have you included MyClass.h in that source file?

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
      [My articles]

      T 1 Reply Last reply
      0
      • C CPallini

        What is the source file the error is given for? Have you included MyClass.h in that source file?

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
        This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
        [My articles]

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

        In adding to the generated classes for SDI application (all the .h files however has #pragma once statements and all .cpp files have #include "stdafx.h" statements) , I am writing a serializable class(CMyclass) that is derived from CObject. In the MyClass.h file, I am including "stdafx.h" (as the header file for CObject and others) file and in the MyClass.cpp file, I am including "MyClass.h" file . Upto this point the application compiles nicely. But whenever I include "MyClass.h" in "MyTrialDoc.h" (in order to create a global object of CMyClass) I get that the compiler limit.When I tried to include #pragma once , I got all the errors which I have mentioned in my previous post.

        Taruni

        C 1 Reply Last reply
        0
        • T Taruni

          In adding to the generated classes for SDI application (all the .h files however has #pragma once statements and all .cpp files have #include "stdafx.h" statements) , I am writing a serializable class(CMyclass) that is derived from CObject. In the MyClass.h file, I am including "stdafx.h" (as the header file for CObject and others) file and in the MyClass.cpp file, I am including "MyClass.h" file . Upto this point the application compiles nicely. But whenever I include "MyClass.h" in "MyTrialDoc.h" (in order to create a global object of CMyClass) I get that the compiler limit.When I tried to include #pragma once , I got all the errors which I have mentioned in my previous post.

          Taruni

          C Offline
          C Offline
          CPallini
          wrote on last edited by
          #6

          The compiler reports the source file under compilation when the error occurs. This piece of info is important, please post it. :)

          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
          This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
          [My articles]

          T 1 Reply Last reply
          0
          • T Taruni

            Hi, I have created an SDI application and created a new class "CMyClass" that is derived from CObject. So I have included the header file "stdafx.h/afx.h " in CMyClass.h. I am trying to create an object of CMyClass in CMyDoc.h and for this purpose I have to include MyClass.h.When I do so and compile I am getting the "warning C4182: #include nesting level is 360 deep; possible infinite recursion" and "fatal error C1076: compiler limit : internal heap limit reached; use /Zm to specify a higher limit". In order to solve the problem , I have maximum tried to minimize the inclusion of header files. But couldn't. How to solve this problem? Thanks in advance.

            Taruni

            K Offline
            K Offline
            krmed
            wrote on last edited by
            #7

            Instead of placing #include in your CMyClass.h, put is as the first line in CMyClass.cpp. That will most likely resolve the problem. Good luck. Karl - WK5M PP-ASEL-IA (N43CS) PGP Key: 0xDB02E193 PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193

            T 1 Reply Last reply
            0
            • K krmed

              Instead of placing #include in your CMyClass.h, put is as the first line in CMyClass.cpp. That will most likely resolve the problem. Good luck. Karl - WK5M PP-ASEL-IA (N43CS) PGP Key: 0xDB02E193 PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193

              T Offline
              T Offline
              Taruni
              wrote on last edited by
              #8

              Thank you krmed. I have even tried that. When I tried to include "stdafx.h" in .cpp files, I am getting the error "error C2504: 'CObject' : base class undefined". As the other alternatives I have even tried including "afx.h" and "afxwin.h" . But in vain.

              Taruni

              1 Reply Last reply
              0
              • C CPallini

                The compiler reports the source file under compilation when the error occurs. This piece of info is important, please post it. :)

                If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                [My articles]

                T Offline
                T Offline
                Taruni
                wrote on last edited by
                #9

                "The compiler reports the source file under compilation when the error occurs" - Pallini are you speaking of "'CMyClass' : is not a class or namespace name" error?

                Taruni

                1 Reply Last reply
                0
                • T Taruni

                  Hi, I have created an SDI application and created a new class "CMyClass" that is derived from CObject. So I have included the header file "stdafx.h/afx.h " in CMyClass.h. I am trying to create an object of CMyClass in CMyDoc.h and for this purpose I have to include MyClass.h.When I do so and compile I am getting the "warning C4182: #include nesting level is 360 deep; possible infinite recursion" and "fatal error C1076: compiler limit : internal heap limit reached; use /Zm to specify a higher limit". In order to solve the problem , I have maximum tried to minimize the inclusion of header files. But couldn't. How to solve this problem? Thanks in advance.

                  Taruni

                  D Offline
                  D Offline
                  David Crow
                  wrote on last edited by
                  #10

                  Taruni wrote:

                  So I have included the header file "stdafx.h/afx.h " in CMyClass.h.

                  Under normal circumstances, there's no need to do this.

                  "Love people and use things, not love things and use people." - Unknown

                  "The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch

                  1 Reply Last reply
                  0
                  • T Taruni

                    Hi, I have created an SDI application and created a new class "CMyClass" that is derived from CObject. So I have included the header file "stdafx.h/afx.h " in CMyClass.h. I am trying to create an object of CMyClass in CMyDoc.h and for this purpose I have to include MyClass.h.When I do so and compile I am getting the "warning C4182: #include nesting level is 360 deep; possible infinite recursion" and "fatal error C1076: compiler limit : internal heap limit reached; use /Zm to specify a higher limit". In order to solve the problem , I have maximum tried to minimize the inclusion of header files. But couldn't. How to solve this problem? Thanks in advance.

                    Taruni

                    D Offline
                    D Offline
                    David Crow
                    wrote on last edited by
                    #11

                    Was your project compiling correctly prior to creating CMyClass? What does the stdafx.h file look like? The top of CMyClass.cpp should look like:

                    #include "stdafx.h"
                    #include "myclass.h"

                    Do you concur?

                    "Love people and use things, not love things and use people." - Unknown

                    "The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch

                    T 1 Reply Last reply
                    0
                    • D David Crow

                      Was your project compiling correctly prior to creating CMyClass? What does the stdafx.h file look like? The top of CMyClass.cpp should look like:

                      #include "stdafx.h"
                      #include "myclass.h"

                      Do you concur?

                      "Love people and use things, not love things and use people." - Unknown

                      "The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch

                      T Offline
                      T Offline
                      Taruni
                      wrote on last edited by
                      #12

                      Thank you David. If I include those header files in .cpp file, then the compiler generates the error as it doesn't find the header file for CObject in MyClass.h file.Again if I include afx.h (which is usually indirectly included by stdafx.h in MyClass.h file in order to solve, the error "compiler limit: internal heap limit is reached " is once again generated.

                      Taruni

                      D 1 Reply Last reply
                      0
                      • T Taruni

                        Thank you David. If I include those header files in .cpp file, then the compiler generates the error as it doesn't find the header file for CObject in MyClass.h file.Again if I include afx.h (which is usually indirectly included by stdafx.h in MyClass.h file in order to solve, the error "compiler limit: internal heap limit is reached " is once again generated.

                        Taruni

                        D Offline
                        D Offline
                        David Crow
                        wrote on last edited by
                        #13

                        Taruni wrote:

                        If I include those header files in .cpp file, then the compiler generates the error as it doesn't find the header file for CObject in MyClass.h file.

                        Which is why I asked what the stdafx.h file looks like. At this point, I would create a "dummy" MFC project, and then create your new class via Insert --> New Class. In the Class Type combobox, select Generic Class. In the Derived From box, type CObject. Study the contents of the files created.

                        "Love people and use things, not love things and use people." - Unknown

                        "The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch

                        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