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. Why have header files?

Why have header files?

Scheduled Pinned Locked Moved C / C++ / MFC
csharpc++javaquestion
6 Posts 6 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
    Anonymous
    wrote on last edited by
    #1

    Why is it that C++ has header files while Java and C# don't?

    S A A P 4 Replies Last reply
    0
    • A Anonymous

      Why is it that C++ has header files while Java and C# don't?

      S Offline
      S Offline
      Scozturk
      wrote on last edited by
      #2

      It is for extending the programming language.. You can create a function which takes many lines to write and put it in a header file so when you need that code again you dont rewrite it but you just include the header file.. Well... I am a beginner ...

      1 Reply Last reply
      0
      • A Anonymous

        Why is it that C++ has header files while Java and C# don't?

        A Offline
        A Offline
        Andrew Walker
        wrote on last edited by
        #3

        Because C++ has to be linked. Compilation units need to know about the declarations of types in other compilation units. Interpreted languages can wait until the VM is running to test whether all required compilation units are present. C++ needs a way of not ending up with duplicate definitions, in multiple compilation units. Header files generally contain just the declarations.


        If you can keep you head when all about you Are losing theirs and blaming it on you; If you can dream - and not make dreams your master; If you can think - and not make thoughts you aim; Yours is the Earth and everything that's in it. Rudyard Kipling

        L 1 Reply Last reply
        0
        • A Anonymous

          Why is it that C++ has header files while Java and C# don't?

          A Offline
          A Offline
          Abin
          wrote on last edited by
          #4

          Actually I hated it when the first time I started to learn Java and C# and found out that they don't have header files, every function body reside in the class definition making the class definition so lengthy and hard to read, sometimes they look like a mess to me. I think I like C++ header files very much.

          1 Reply Last reply
          0
          • A Anonymous

            Why is it that C++ has header files while Java and C# don't?

            P Offline
            P Offline
            PengFeidu
            wrote on last edited by
            #5

            it make you clearer for your Class definition. at the same time ,It is a good iead to protected your source code. dupengfei

            1 Reply Last reply
            0
            • A Andrew Walker

              Because C++ has to be linked. Compilation units need to know about the declarations of types in other compilation units. Interpreted languages can wait until the VM is running to test whether all required compilation units are present. C++ needs a way of not ending up with duplicate definitions, in multiple compilation units. Header files generally contain just the declarations.


              If you can keep you head when all about you Are losing theirs and blaming it on you; If you can dream - and not make dreams your master; If you can think - and not make thoughts you aim; Yours is the Earth and everything that's in it. Rudyard Kipling

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              Rudyard Kipling is wrong; The Earth can never be yours, nor everything that is in it!

              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