Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1046585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T16:10:07+00:00 2026-05-16T16:10:07+00:00

Consider the following: PImpl.hpp class Impl; class PImpl { Impl* pimpl; PImpl() : pimpl(new

  • 0

Consider the following:

PImpl.hpp

class Impl;

class PImpl
{
    Impl* pimpl;
    PImpl() : pimpl(new Impl) { }
    ~PImpl() { delete pimpl; }
    void DoSomething();
};

PImpl.cpp

#include "PImpl.hpp"
#include "Impl.hpp"

void PImpl::DoSomething() { pimpl->DoSomething(); }

Impl.hpp

class Impl
{
    int data;
public:
    void DoSomething() {}
}

client.cpp

#include "Pimpl.hpp"

int main()
{
    PImpl unitUnderTest;
    unitUnderTest.DoSomething();
}

The idea behind this pattern is that Impl‘s interface can change, yet clients do not have to be recompiled. Yet, I fail to see how this can truly be the case. Let’s say I wanted to add a method to this class — clients would still have to recompile.

Basically, the only kinds of changes like this that I can see ever needing to change the header file for a class for are things for which the interface of the class changes. And when that happens, pimpl or no pimpl, clients have to recompile.

What kinds of editing here give us benefits in terms of not recompiling client code?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T16:10:08+00:00Added an answer on May 16, 2026 at 4:10 pm

    The main advantage is that the clients of the interface aren’t forced to include the headers for all your class’s internal dependencies. So any changes to those headers don’t cascade into a recompile of most of your project. Plus general idealism about implementation-hiding.

    Also, you wouldn’t necessarily put your impl class in its own header. Just make it a struct inside the single cpp and make your outer class reference its data members directly.

    Edit: Example

    SomeClass.h

    struct SomeClassImpl;
    
    class SomeClass {
        SomeClassImpl * pImpl;
    public:
        SomeClass();
        ~SomeClass();
        int DoSomething();
    };
    

    SomeClass.cpp

    #include "SomeClass.h"
    #include "OtherClass.h"
    #include <vector>
    
    struct SomeClassImpl {
        int foo;
        std::vector<OtherClass> otherClassVec;   //users of SomeClass don't need to know anything about OtherClass, or include its header.
    };
    
    SomeClass::SomeClass() { pImpl = new SomeClassImpl; }
    SomeClass::~SomeClass() { delete pImpl; }
    
    int SomeClass::DoSomething() {
        pImpl->otherClassVec.push_back(0);
        return pImpl->otherClassVec.size();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 513k
  • Answers 513k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Select your Project in Solution Explorer. Right click it and… May 16, 2026 at 5:58 pm
  • Editorial Team
    Editorial Team added an answer Some things to take note of: When two balls, each… May 16, 2026 at 5:58 pm
  • Editorial Team
    Editorial Team added an answer Looks like you might be able to optimize your design… May 16, 2026 at 5:58 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Consider following example : public class SomeBusinessLayerService : DataService<MyEntityContainer> { [WebInvoke] void DoSomething(string someParam)
Consider following example. #include <iostream> #include <algorithm> #include <vector> #include <boost/bind.hpp> void func(int e,
Consider following class class test { public: test(int x){ cout<< test \n; } };
Consider following example: #include <iostream> #include <functional> #include <algorithm> #include <vector> #include <boost/bind.hpp> const
Consider following program: static void Main (string[] args) { int i; uint ui; i
Consider the following Scala case class: case class WideLoad(a: String, b: Int, c: Float,
Consider the following code: class Program { static void Main(string[] args) { A a
Consider the following simple example: [DataContract({0}Base)] public class Base<T> where T : Entity<T> {
Consider following: Partial View: <%= Html.ListBox(BlackList, Model.Select( x => new SelectListItem { Text =
Consider the following models: class Person(models.Model): name = models.CharField(max_length=128) class Group(models.Model): name = models.CharField(max_length=128)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.