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.

281 questions
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
  • 20,097
  • 26
  • 114
  • 195
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
  • 244
  • 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
  • 753
  • 7
  • 17
-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

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
  • 451
  • 2
  • 7
-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
  • 17,706
  • 12
  • 64
  • 134
-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
  • 462
  • 2
  • 14
-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
  • 150
  • 1
  • 7
-1
votes
2 answers

Error deleting std::vector in a DLL using the PIMPL idiom

I have the following code: In DLL1: in .h file: class MyClass { public: MyClass(); private: std::string m_name; }; class __declspec(dllexport) Foo { private: struct Impl; Impl *pimpl; public: Foo(); virtual…
Igor
  • 4,364
  • 8
  • 38
  • 80
-1
votes
1 answer

Qt: Objective-C header gets compiled as c++-header

I'm currently trying to implement the PIMPL-Idiom to encapsulate Objective-C functionality in a C++ class in Qt. My pro file looks as it follows: QT += core gui TARGET = testProject TEMPLATE = app SOURCES += main.cpp Helper.cpp HEADERS +=…
ParkerHalo
  • 4,104
  • 9
  • 25
  • 47
-2
votes
3 answers

Invoking constructor through PIMPL idiom design

/*Process.h*/ class Process { public: Process(ProcessID thirdParty_pid); protected: void createImpl(); private: ProcessImpl * _impl; }; /*ProcessImpl.h*/ class ProcessImpl { public : ProcessImpl(ProcessID…
user2380779
  • 11
  • 1
  • 5
1 2 3
18
19