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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. Simple question about header files

Simple question about header files

Scheduled Pinned Locked Moved Managed C++/CLI
question
6 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.
  • V Offline
    V Offline
    Virtek
    wrote on last edited by
    #1

    I've got two header files: // This is file1.h #include "file2.h" __gc class Class1 { .... }; // This is file2.h #include "file2.h" __gc class Class2 { .... } I want both files to "know" each other, but it becomes an endless loop when i try to #include each other... Any idia ? Thanks

    V 2 D 3 Replies Last reply
    0
    • V Virtek

      I've got two header files: // This is file1.h #include "file2.h" __gc class Class1 { .... }; // This is file2.h #include "file2.h" __gc class Class2 { .... } I want both files to "know" each other, but it becomes an endless loop when i try to #include each other... Any idia ? Thanks

      V Offline
      V Offline
      Virtek
      wrote on last edited by
      #2

      Correction about the file2.h file: #include "file1.h" of-course

      M 1 Reply Last reply
      0
      • V Virtek

        I've got two header files: // This is file1.h #include "file2.h" __gc class Class1 { .... }; // This is file2.h #include "file2.h" __gc class Class2 { .... } I want both files to "know" each other, but it becomes an endless loop when i try to #include each other... Any idia ? Thanks

        2 Offline
        2 Offline
        2bee
        wrote on last edited by
        #3

        Hi Virtek, cross including seems kinda up to date problem. I would suggest that you add #pragma once to both of your header files. #pragma once "Specifies that the file will be included (opened) only once by the compiler when compiling a source code file." Furthermore those two threads might be interesting to you as well. http://www.codeproject.com/script/comments/forums.asp?msg=1401063&forumid=3785#xx1401063xx http://www.codeproject.com/script/comments/forums.asp?msg=1422933&forumid=3785#xx1422933xx regards Tobias

        1 Reply Last reply
        0
        • V Virtek

          Correction about the file2.h file: #include "file1.h" of-course

          M Offline
          M Offline
          mcljava
          wrote on last edited by
          #4

          Fundamental to the header files is the preprocessor. In order to avoid Multi-Inclusion you need a to tell the preprocessor to only include the header under certain conditions. For example, file1.h #ifndef __FILE_1_H__ #define __FILE_1_H__ ... #endif Now with that said, you probably need to revisit your header file design because you should not have a situation where File1 is including File2 and visa versa. If there is common definitions or structures, put those in a separate header. Keep the module specific data in the header that applies to the .CPP or .C module. You application might then look like: file1.h #include "File1.h" #include "CommonData.h" ... file2.h would be similar. Good Luck Mike Luster CTI/IVR/Telephony SME

          1 Reply Last reply
          0
          • V Virtek

            I've got two header files: // This is file1.h #include "file2.h" __gc class Class1 { .... }; // This is file2.h #include "file2.h" __gc class Class2 { .... } I want both files to "know" each other, but it becomes an endless loop when i try to #include each other... Any idia ? Thanks

            D Offline
            D Offline
            Divyang Mithaiwala
            wrote on last edited by
            #5

            Do you know why C apply .h & .c file concept. Becoz in .h file you do all declaration & in .c file you define all function. so what you do for both header file make .c/.cpp file(which you already done.). & include file1.h in file2.cpp & file2.h in file1.cpp. so it is not endless loop.


            Divyang Mithaiwala System Engineer & Software Developer

            S 1 Reply Last reply
            0
            • D Divyang Mithaiwala

              Do you know why C apply .h & .c file concept. Becoz in .h file you do all declaration & in .c file you define all function. so what you do for both header file make .c/.cpp file(which you already done.). & include file1.h in file2.cpp & file2.h in file1.cpp. so it is not endless loop.


              Divyang Mithaiwala System Engineer & Software Developer

              S Offline
              S Offline
              Saksida Bojan
              wrote on last edited by
              #6

              Divyang Mithaiwala wrote:

              so it is not endless loop.

              It is. Unless you add the folowing

              #ifndef _FILE1_H_ // At the beginning of .h file
              #define _FILE1_H_ // Win32 style for declaring .h file

              #endif // at the end of .h file

              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