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
4 answers

Remove dependancy constants from enum definition

I am trying to safely remove a dependency from my project by using opaque structures and forward declarations but like most I am still stuck on my enums. The header file dependency I am trying to remove from my header files has defined constants…
Charles
  • 3,734
  • 3
  • 31
  • 49
0
votes
2 answers

Segfault when trying to access function of member in a library

I have a library that is all tested thoroughly through google test suite. I am trying to keep it "pimpl" clean, but I'm running into a segfault I can't quite figure out. Relevant Code: Interface.h: class Interface{ public: Interface(); void…
shavera
  • 803
  • 1
  • 8
  • 18
0
votes
0 answers

Strange behaviour visual studio dll and .exe?

I am having a very weird result with some code: I am using boost.any (before was using void *) to return an address from a .dll in a .exe. The dll has a function like this: boost::any User::getNativeHandle() { return…
Germán Diago
  • 7,473
  • 1
  • 36
  • 59
0
votes
2 answers

How to use Loki's Pimpl implementation?

Link to source code of Loki Pimpl header. I am not able to find any documentation on how to use the same, can any one explain how to use. And what does the following function in the header do. PimplOwner ImplOf PimplOf RimplOf
Passionate programmer
  • 5,748
  • 10
  • 39
  • 43
0
votes
1 answer

Cannot insert user-defined into an encapsulated vector using pimpl idiom

I have an issue on using my Push function on the TokenList class where I encapsulated the vector of Tokens. Whenever I call the Push function, the member variable word inside Token class was empty even when I initialize the Token variable properly.…
Kenneth Bastian
  • 843
  • 1
  • 8
  • 10
0
votes
2 answers

C4150: Deletion of pointer to incomplete type and PIMPL idiom

is there any way to properly implement the PIMPL idiom with a template class in C++? For example, I have the following PIMPL class: template struct PrivateImplementation { PrivateImplementation(T* impl) : implementation(impl) { …
Xenoprimate
  • 7,691
  • 15
  • 58
  • 95
0
votes
1 answer

Is there any reason that the following pimpl-like implementation wouldn't work?

Here I asked a question about trying to avoid polluting my codebase with content from the window.h file so as to make sure my codebase is cross-platform compatible. I was shown that the general idea that I'd come up with with referred to the pimpl…
Darinth
  • 511
  • 3
  • 14
0
votes
1 answer

PImpl template in Objective-C

I'm trying to use the PImpl idiom to use the libray in my Objective-C project. I have managed to implement it, but it only for the Int type as you can see in my .h and .mm file. file.h #import struct…
Artanis
  • 15
  • 3
0
votes
1 answer

Accessing C++ class public member function from private struct data member

This might be a trivial C++ semantics question, I guess, but I'm running into issues on Windows (VS2010) with this. I have a class as follows: class A { public: some_type some_func(); private: struct impl; boost::scoped_ptr
squashed.bugaboo
  • 1,338
  • 2
  • 20
  • 36
0
votes
1 answer

How to fix expected primary-expression COMPILE ERROR in a pimpl implementation?

BACKGROUND I have two implementations of coord_t simp_t that simply stores x,y dep_t which takes a dependent parent coord_t and adds an offset to it These are lower-level implementation classes. At the user level, the usage should look like…
kfmfe04
  • 14,936
  • 14
  • 74
  • 140
0
votes
1 answer

How to use the pImpl idiom in the public interface of a DLL library?

The standard implementation of the pImpl idiom puts the following code in the .h file: class MyClassImpl; class MyClass { public: MyClass(); ~MyClass(); MyClass(const MyClass&); MyClass& operator=(const MyClass&); private: …
Michal Czardybon
  • 2,795
  • 4
  • 28
  • 40
0
votes
1 answer

Add singleton feature to Pimpl class

I'm having some trouble converting a working pimpl class to singleton. Here is the starting code: apirequest.h class ApiRequestPrivate; class ApiRequest { public: ApiRequest( int ); ~ApiRequest( ); int method1(); private: …
bullet
  • 83
  • 7
0
votes
1 answer

class library and pimpl - splitting class accessibility

I want to make a class-library using pimpl idiom, so that I can hide my implementation details for the user of the library. Is it possible, to make a class, where some methods are public and callable from users perspective, while having methods that…
abaldur
  • 29
  • 1
  • 3
0
votes
3 answers

Strange "type class::method() : stuff " syntax C++

While reading some stuff on the pImpl idiom I found something like this: MyClass::MyClass() : pimpl_( new MyClassImp() ) First: What does it mean? Second: What is the syntax? Sorry for being such a noob.
da_petcu21
  • 527
  • 4
  • 15
0
votes
1 answer

Can a class with pimpl use an object with pimpl?

Pimpl is short for "pointer to implementation" and offers a handy way to hide away implementations in classes. I'm implementing a Window-class, which hides platform-specific functions and structures from user of this class, and so the class…
Helixirr
  • 911
  • 9
  • 18