Questions tagged [pimpl-idiom]

The PIMPL idiom, also known as the compilation firewall or Cheshire Cat technique, is a "private implementation" technique useful in C++ and other similar statically compiled languages.

The idiom makes use of an opaque pointer to another object (usually of a nested class type) which provides the implementation. Member functions on the outer object forward to the implementation object, which is defined in a separate source file so that the implementation is not visible in the header defining the outer class. This is a special case of the Bridge pattern.

The term Cheshire Cat (because the body disappears leaving only a smile) is older, but the more common name PIMPL idiom was popularized by Herb Sutter in GOTW #24 (and revisited in GOTW #100 and #101).

Links:

Separating Interface and Implementation in C++ compares the PIMPL idiom to other related techniques.

318 questions
0
votes
1 answer

Hide implementation details via internal pointer

I have following third-party class(just wrapper around some pointer): // a.h class AImpl; class A { AImpl* pImpl; public: A(): pImpl(0) {} A(AImpl* ptr): pImpl(ptr) {} ... AImpl* getImpl() const { return pImpl; } ... …
user2547823
  • 11
  • 1
  • 2
0
votes
2 answers

Is it possible to wrap boost sockets with Pimpl?

in a project we want to wrap the Boost Asio socket in a way, that the using class or the wrapping .h does not have to include the boost headers. We usually use pointers and forward declarations for wrapped classes. Foward declaration: namespace…
Tarnschaf
  • 3,955
  • 1
  • 26
  • 36
0
votes
1 answer

c++ pimpl and abstract class together

Please take a look at the following code (a code is worth a thousand words): shape.hpp class Shape { public: double area() const; private: class ShapeImpl; ShapeImpl* pimpl; }; shape.cc // ABS class Shape::ShapeImpl { public: …
montefuscolo
  • 259
  • 2
  • 13
0
votes
2 answers

C++ how do I make a 2d engine platform independent

Create a simple 2D sprite engine with a cross platform, abstracted API ■ The demo should be completely cross platform and have no platform specific headers ■ The cross platform code is isolated completely from platform dependent code, in that there…
0
votes
2 answers

Objective-C instance into C++ class

How I can instantiate a Objective-c class into CPP class? for example my CPP class: class Foo{ public: Foo(); private: MyObjcClass* myObjcClass; //it does not work } how I can do this? note I using .m for Objective-C and .cpp for…
ademar111190
  • 14,215
  • 14
  • 85
  • 114
0
votes
1 answer

How to consume a C# class from C++/CLI using PIMPL

I need to consume a C# class from an unmanaged application. Say I have the following C# class: public class Managed { public void Subcribe(int handler) { .... } } Then I create the following C++/CLI class: /// Header class…
Ignacio Soler Garcia
  • 21,122
  • 31
  • 128
  • 207
0
votes
2 answers

Declare variables in unnamed namespace

In my current job, I am seeing variables declared in the unnamed namespace in the cpp file and used only by that class as if they are member variables. I see it as an interesting way of keeping only interface information in .h and implmentation in…
Lap
  • 254
  • 2
  • 9
0
votes
1 answer

Templated pimpl forwarding

I have a bunch of related indicies in a kind of templated hierarchy, looking something like template struct index{ index w; int x, y; }; template <> struct index<0> { int x, y; }; template struct…
zounds
  • 773
  • 8
  • 17
-1
votes
1 answer

How to avoid shared_ptr overhead when doing PIMPL

AFAIK unique_ptr is quite tricky to use with PIMPL, since deleter is part of unique_ptr type so it will not work with incomplete types. On the other hand shared_ptr uses dynamic deleter so it works with incomplete types. shared_ptr has the…
NoSenseEtAl
  • 28,205
  • 28
  • 128
  • 277
-1
votes
1 answer

Qt and Pimpl: double free or corruption (out)

i wanna write a qt c++ lib using the pimpl idiom. Based on this post How to use the Qt's PIMPL idiom? i have written a little program. Compiling and running is ok but if i wanna close the client with deleteLater() the Prog raise an error: Client:…
yves84
  • 1
-1
votes
1 answer

Dynamic switching of implementation in hardware abstraction layer (HAL)

I'm trying to implement a hardware abstraction layer (HAL) to access several similar devices using all the same interface. The question is, how should I implement the dynamic switching of the implementation for one device class vs. another. The…
-1
votes
1 answer

Does pimpl design pattern prevent you from compilation?

According to this article, it's trying to explain the problem which pimpl solve but i see that there is no problem in example he showed. It says that: "there is an issue with below design (that could be serious or not, depending on how many…
Islam Abdeen
  • 539
  • 3
  • 10
-1
votes
2 answers

What are the risks of using non exposed type in the public headers

I am developing a library where one of its public interface class defined as: class speed: public: //constructors, operators, setter, getters... private: float x,y,z; }; I think here that I am re-inventing the wheel again. Using something…
Humam Helfawi
  • 19,566
  • 15
  • 85
  • 160
-1
votes
2 answers

C++ pimpI mutex preventing usage of std::condicition_variable

C++/CLI is known to block the mutex header when a project is compiled using the -clr:pure or clr flag. The error is reported…
Johan
  • 502
  • 4
  • 18
-1
votes
1 answer

"api design for c++": c++ pimple access

I'm trying to understand a pimple example from the "api design for c++" book (page 70). // autotimer.h class AutoTimer { public: explicit AutoTimer(const std::string &name); AutoTimer(); // allow access from other classes/functions in…
user14419
  • 160
  • 1
  • 7
1 2 3
21
22