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

  • Home
  • SEARCH
  • 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 9120945
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:44:41+00:00 2026-06-17T05:44:41+00:00

class MyClassPrivate { //My members. }; //and then class MyClass { private: MyClassPrivate* const

  • 0
class MyClassPrivate
{
//My members.
};    

//and then
class MyClass {
private:
 MyClassPrivate* const d;
};

What is the reason of using this ‘pattern’? How it’s correctly called?

  • 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-06-17T05:44:43+00:00Added an answer on June 17, 2026 at 5:44 am

    The most usage is Pimlp idiom.

    • Why should the “PIMPL” idiom be used?
    • Pimpl idiom
    • The Pimpl

    The Pimpl idiom describes a way for making your header files
    impervious to change. You often hear advices like “Avoid change your
    public interface!” So you can modify your private interface, but how
    can you avoid recompilation when your header file defines the private
    methods. This is what the Pimpl does – Reduce compilation damages when
    your private interface changes[3].

    From Here:

    Benefits:

    1. Changing private member variables of a class does not require recompiling classes that depend on it, thus make times are faster, and the FragileBinaryInterfaceProblem is reduced.
    2. The header file does not need to #include classes that are used ‘by value’ in private member variables, thus compile times are faster.
    3. This is sorta like the way SmallTalk automatically handles classes… more pure encapsulation.

    Drawbacks:

    1. More work for the implementer.
    2. Doesn’t work for ‘protected’ members where access by subclasses is required.
    3. Somewhat harder to read code, since some information is no longer in the header file.
    4. Run-time performance is slightly compromised due to the pointer indirection, especially if function calls are virtual (branch prediction for indirect branches is generally poor).

    How to do it:

    1. Put all the private member variables into a struct.
    2. Put the struct definition in the .cpp file.
    3. In the header file, put only the ForwardDeclaration of the struct.
    4. In the class definition, declare a (smart) pointer to the struct as the only private member variable.
    5. The constructors for the class need to create the struct.
    6. The destructor of the class needs to destroy the struct (possibly implicitly due to use of a smart pointer).
    7. The assignment operator and CopyConstructor need to copy the struct appropriately or else be disabled.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This isn't valid code: public class MyClass { private static boolean yesNo = false;
If I have a simple class setup like this: class MyClass { private string
The default way to implement singleton pattern is: class MyClass { private static MyClass
Okay, I have something like this in C++: class MyClass{ private: int someVariable; int
I have a class like this: public class MyClass { private Queue<MyOtherClass> myQueue; }
Consider this code snippet: class MyClass{ private List myList; //... public List getList(){ return
I have this sample code public class MyClass { private static int tempKey =
Take this code: public class MyClass { private final Object _lock = new Object();
This is first way: Public Class MyClass Private _Property As String Property Property ()
Suppose I have a class like this: class MyClass { private: vector<MyOtherClass> myMember; public:

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.