CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Threaded View

  1. #1
    Join Date
    Jul 2017
    Location
    Greece
    Posts
    130

    Do header files with implementation work in a precompiled header?

    Let's suppose we have this header file:

    People.h
    Code:
    class People
    {
        public:
        People(const std::string &name, int age)
            : m_name(name), m_age(age)
        {
        }
    
        inline const std::string& GetName() const { return m_name; }
        inline int GetAge() const { return m_age; }
    
        inline std::string ToString() const { std::stringstream ss; ss << m_name << " , " << m_age; return ss.str(); }
    
    
        private:
        std::string m_name;
        int m_age;
    };
    pch.h
    Code:
    #include "People.h"
    If you include a header file like that in a precompiled header, will it work!

    If you include that pch.h in a bunch of .cpp files, you basically include People.h too. So if I make changes to that .cpp files, wouldn't People.h be recompiled each time too?

    Also what happens if I have something like this:
    MyClass.h
    Code:
    #include "People.h"
    class MyClass
    {
        public:
        MyClass();
        
         //Allocate on the stack.
         People people("name", 20);
    }
    MyClass.cpp
    Code:
    #include "pch.h"
    #include "MyClass.h"
    
    //implementation of MyClass
    Will the above recompile People.h every time I make changes?
    Last edited by babaliaris; September 11th, 2020 at 06:26 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured