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. C / C++ / MFC
  4. Interview question

Interview question

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++graphicscareer
3 Posts 2 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
    AkashAg
    wrote on last edited by
    #1

    Hi All, I have been asked these question in a telephonic interview: 1) Why some header files have there definitions in itslef and don't have a '.cpp' for definition? Classic examples are vector.h and other STL files. What will be the impact of having definitions in a separate cpp file/ 2) What is the disadvantage if I make all my functions inline and inline request is always acknowledged by the compiler? I told him that recursion is not possible, load time will be more, page faults will be more, binary size will increase. But he was looking for some other things as well. It will be very much helpful if someone can fulfill these queries with explanatory notes. BR, Akash

    A 1 Reply Last reply
    0
    • A AkashAg

      Hi All, I have been asked these question in a telephonic interview: 1) Why some header files have there definitions in itslef and don't have a '.cpp' for definition? Classic examples are vector.h and other STL files. What will be the impact of having definitions in a separate cpp file/ 2) What is the disadvantage if I make all my functions inline and inline request is always acknowledged by the compiler? I told him that recursion is not possible, load time will be more, page faults will be more, binary size will increase. But he was looking for some other things as well. It will be very much helpful if someone can fulfill these queries with explanatory notes. BR, Akash

      A Offline
      A Offline
      Aescleal
      wrote on last edited by
      #2

      1. Most compilers don't support the export so you really need the definition of a template class in with it's declaration of you can't use the template class with arbitrary type parameters. The main impact of having everything in an h file is that it couples the class in the h file more tightly with your code. FREX if the implementation of std::vector changes everything that includes vector has to be recompiled. If export was supported you'd just need to compile vector.cpp and relink (and maybe do that intermediate step thing that EDG does when using exported templates) which would be a lot faster. 2. In addition to your comments the main problem is again dependencies. When you modify your class implementation (if it's all in an h file) you have to recompile ALL the source files that use that class. This can increase build times through the roof for a simple change. Incidentally recursion would still be possible - a clever compiler could convert your inlined recursion into iteration. Cheers, Ash

      A 1 Reply Last reply
      0
      • A Aescleal

        1. Most compilers don't support the export so you really need the definition of a template class in with it's declaration of you can't use the template class with arbitrary type parameters. The main impact of having everything in an h file is that it couples the class in the h file more tightly with your code. FREX if the implementation of std::vector changes everything that includes vector has to be recompiled. If export was supported you'd just need to compile vector.cpp and relink (and maybe do that intermediate step thing that EDG does when using exported templates) which would be a lot faster. 2. In addition to your comments the main problem is again dependencies. When you modify your class implementation (if it's all in an h file) you have to recompile ALL the source files that use that class. This can increase build times through the roof for a simple change. Incidentally recursion would still be possible - a clever compiler could convert your inlined recursion into iteration. Cheers, Ash

        A Offline
        A Offline
        AkashAg
        wrote on last edited by
        #3

        thanks Aescleal :)

        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