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
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
  • 6,942
  • 15
  • 51
  • 89
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
  • 496
  • 2
  • 13
0
votes
1 answer

pimpl template in objective C

I'm trying to use the pimpl idiom to use the libray in XCode 5.0 in my Objctive 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,267
  • 2
  • 19
  • 34
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,193
  • 11
  • 67
  • 132
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,685
  • 4
  • 27
  • 39
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
  • 57
  • 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
  • 467
  • 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
  • 817
  • 6
  • 17
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,795
  • 1
  • 23
  • 32
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
  • 219
  • 2
  • 12
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
  • 13,115
  • 12
  • 74
  • 101
1 2 3
18
19