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. What if...???

What if...???

Scheduled Pinned Locked Moved C / C++ / MFC
c++questiondiscussion
7 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.
  • C Offline
    C Offline
    Cristoff
    wrote on last edited by
    #1

    What do you think if I implement my classes in .h files instead of dividing the declarations in .h files and the implementation in .cpp? Is this a bad programming style or it will bother the compiler?

    M T B M C 5 Replies Last reply
    0
    • C Cristoff

      What do you think if I implement my classes in .h files instead of dividing the declarations in .h files and the implementation in .cpp? Is this a bad programming style or it will bother the compiler?

      M Offline
      M Offline
      misturas
      wrote on last edited by
      #2

      For me it seems strange, :doh: I know that AppWizard makes the reverse for CAboutDlg of a single/multidocument app It inserts the declaration in .cpp before the implementation I think it's better the usual way

      1 Reply Last reply
      0
      • C Cristoff

        What do you think if I implement my classes in .h files instead of dividing the declarations in .h files and the implementation in .cpp? Is this a bad programming style or it will bother the compiler?

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

        it wont bother that much the compiler if you do it correctly. however, it is a bad habit to do so. we generally put into headers only declarations, other includes, class definitions, and the implementation code into deparated .cpp files...


        TOXCCT >>> GEII power
        [toxcct][VisualCalc 2.20]

        B 1 Reply Last reply
        0
        • C Cristoff

          What do you think if I implement my classes in .h files instead of dividing the declarations in .h files and the implementation in .cpp? Is this a bad programming style or it will bother the compiler?

          B Offline
          B Offline
          Bob Stanneveld
          wrote on last edited by
          #4

          Hello, It's a bad (C/C++) programming practice and it will bother the linker if you include the header in more than one place. (Multiple defined symbols...). Besides that, if you place all your code in header files (no *.cpp file(s)) you'll not be able to create object files and executable code... If you are talking about templates (I assume you are not), then you have to put all the code in a *.inl document or in the header file. Hope this helps you. :) Behind every great black man...             ... is the police. - Conspiracy brother Blog[^]

          1 Reply Last reply
          0
          • C Cristoff

            What do you think if I implement my classes in .h files instead of dividing the declarations in .h files and the implementation in .cpp? Is this a bad programming style or it will bother the compiler?

            M Offline
            M Offline
            Maximilien
            wrote on last edited by
            #5

            bad idea, if you change the implementation all file dependant on that header file will be recompiled. Also, I don't think the debugger will be able to step in the code. anyway, bad idea, I sure others will give you other reasons why.


            Maximilien Lincourt Your Head A Splode - Strong Bad

            1 Reply Last reply
            0
            • T toxcct

              it wont bother that much the compiler if you do it correctly. however, it is a bad habit to do so. we generally put into headers only declarations, other includes, class definitions, and the implementation code into deparated .cpp files...


              TOXCCT >>> GEII power
              [toxcct][VisualCalc 2.20]

              B Offline
              B Offline
              Bob Stanneveld
              wrote on last edited by
              #6

              toxcct wrote:

              it wont bother that much the compiler if you do it correctly.

              It doesn't bother the compiler, but it bothers the linker. Behind every great black man...             ... is the police. - Conspiracy brother Blog[^]

              1 Reply Last reply
              0
              • C Cristoff

                What do you think if I implement my classes in .h files instead of dividing the declarations in .h files and the implementation in .cpp? Is this a bad programming style or it will bother the compiler?

                C Offline
                C Offline
                Cristoff
                wrote on last edited by
                #7

                Thank you everyone.

                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