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.

Filter by
Sorted by
Tagged with
4 votes
2 answers
65 views

CMake: transitive dependency linking of static libs "in-place" instead of appending

the title may be a bit too short to be clear enough. We have a complex C/C++-project which is built and linked in a lot of separate targets as static libraries. So my problem is that the ...
NetoBF's user avatar
  • 127
2 votes
1 answer
86 views

pimpl, std::unique_ptr and constexpr constructor

I'm reviewing a non-compiling code where I find a design similar to this: B.h #include <memory> class A; class B { private: int val; // pImpl idiom std::unique_ptr<A> ...
Oersted's user avatar
  • 893
0 votes
0 answers
49 views

declaration and default initialization of member-variables in PIMPL interfaces?

We are developping an embedded project, where we use C++14 and PIMPL for the OS-Abstraction. So we have Task-PIMPL-Interface which gets implemented in the referenced operating-system-SDK. Currently a ...
NetoBF's user avatar
  • 127
1 vote
1 answer
79 views

Pimpl idiom through macro

I try to reduce code duplication in a class which implements the pimpl idiom. Imagine I have a header Foo.h. For better readability, I have reduced the methods. class FooImp; class Foo { public: ...
RoQuOTriX's user avatar
  • 2,879
2 votes
0 answers
104 views

unique_ptr in PImpl and ABI compatibility

Consider a standard class implementation that makes use of PImpl, but uses a std::unique_ptr to manage the implementation object's lifetime: class MyClass { public: class Impl; MyClass(); ...
Raven's user avatar
  • 3,011
0 votes
1 answer
52 views

using pimpl pattern in templated class. How to allocate a unique_ptr

My colleague insists our project should be able to use a template like this: template <typename T, typename B> class Foo { public: Foo(T t, B b); // some more functions private: ...
Jeffrey's user avatar
  • 11.1k
0 votes
0 answers
105 views

How to use pimpl idiom with templated functions

I have a class which has a template member functions and the private members needs to be put in the implementation class by pimpl idiom approach. Foo.hpp #include <iostream> class Foo { public: ...
Tharani B's user avatar
1 vote
2 answers
196 views

Can you use the pimpl idiom for use across multiple cpp files with one class?

For instance, here is what I mean. Let's say you have a single header file with a single pimpl class. Can you define the functions of this class across two cpp files without redefining the variables ...
F35H's user avatar
  • 25
2 votes
2 answers
225 views

"multiply defined symbols found" how is my destructor being defined twice?

Question: What am I doing to cause a multiple definition symbol linker error? OSFrameworkWindows10Module.ixx module; #include <memory> export module OSFrameworkWindows10Module; export class ...
Teeeeeeeeeeeeeeeeeeeeeeeeeeeej's user avatar
1 vote
1 answer
47 views

pImpl pattern in C++ needs complete definition of impl subclass

I've looked at many of the SO questions on pImpl, unique_ptr and forward declarations, but can't figure out what is wrong. The answer at Is std::unique_ptr<T> required to know the full ...
GaryO's user avatar
  • 5,945
5 votes
1 answer
201 views

C++ pimpl idiom: return impl pointer in getter of API class [closed]

I use the pimpl idiom for classes in the public API of my library to benefit from it's properties like ABI stability. In my non-public code it would be convenient to have access to the impl object to ...
Jus Gru's user avatar
  • 106
0 votes
1 answer
70 views

looking for a design pattern for complex numbers class in c++

I'm using complex numbers for learning design patterns. I'm currently using an abstract class: namespace abstract{ class complex{ public: virtual ~complex() = 0; ...
Eric Cardozo's user avatar
0 votes
1 answer
62 views

How can I offload dependency injected template class providing templated functions to pimpl class

I have an application class that can take in a dependent class as a template argument to the constructor. This dependent class is required to provide certain templated functions that the application ...
atab's user avatar
  • 1
1 vote
0 answers
63 views

Using PIMPL but single header + multiple cpp files

I have a header file class.hpp that contains my main object class Class { public: Class(); ~Class(); private: struct Impl; std::unique_ptr<Impl> impl; }; I then have my main ...
raaj's user avatar
  • 2,891
0 votes
0 answers
96 views

How to get rid of these static_casts?

I'm trying to create a C++ class hierarchy of UI "view" classes that wrap platform-specific UI classes. My classes use the pimpl idiom to hide the implementation from the header file. The ...
Rob N's user avatar
  • 15.1k
1 vote
0 answers
130 views

How can I implement the PIMPL idiom in a thread-safe manner?

I have a class that is implemented using the PIMPL idiom. A single instance of this class will be used across multiple threads within a multithreaded program. Inside the implementation of the class I ...
tjwrona1992's user avatar
  • 8,624
0 votes
0 answers
28 views

How to provide an opaque public handle in public API while still able to touch the implementation detail inside internal component?

I am refactoring a biometric recognition SDK, which public API provide feature extraction and some CRUD feature management interface like: class PublicComponent{ public: FeaturePublic ...
user8510613's user avatar
  • 1,242
0 votes
3 answers
99 views

About the pimpl syntax

I have a question about the C++ usage used in the pimpl syntax. First, why is it not necessary to write pimpl( new impl ) as pimpl( new my_class::impl ) Second, why is the lifetime of new impl ...
gahhu's user avatar
  • 31
3 votes
0 answers
193 views

C++ PIMPL using std::unique_ptr and rule of five

If having a c++ class with a pimpl using std::unique_ptr and solving the fact that the pimpl class is incomplete in the header by declaring my own destructor (I know i could also provide a custom ...
joaerl's user avatar
  • 1,012
0 votes
1 answer
107 views

C++ abi compatability without pimpl using abstract class

Suppose I have a class B_Impl which inherits and implements a pure abstract class B (not containing any data-fields). Suppose class A uses B_Impl via B* only. If I add a field to B_Impl.h (clearly, ...
JenyaKh's user avatar
  • 2,070
16 votes
1 answer
492 views

Why does = default member initializer request instantiation of unique_ptr destructor while {} does not?

This is a follow up of this question: Does PIMPL idiom actually work using std::unique_ptr? The full example uses multiple files, so for the sake of this question I will reduce it here. The full ...
463035818_is_not_an_ai's user avatar
1 vote
1 answer
73 views

Max Heap built with pimpl in c++ not working properly

I have a class built using the pimpl idiom that represents a binary max Heap and it is not working properly: the program compiles and prints the content of the array but the array is not sorted ...
Spyromancer's user avatar
2 votes
1 answer
465 views

Constructor and destructor in c++ when using the pimpl idiom

I come from Java that has a different way in handling what's private and has to be hided regarding a class implementation and it also has a garbage collector which means there is no need for a ...
Spyromancer's user avatar
1 vote
1 answer
231 views

Having a typedef in the source file and a member variable in header

I have a class structure where I have some member variables declared like this: /* HEADER */ #ifndef SRC_HEADER_H #define SRC_HEADER_H class Service { private: typedef boost::multi_index_container&...
Vaibhav's user avatar
  • 346
-1 votes
1 answer
246 views

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 ...
NoSenseEtAl's user avatar
  • 28.4k
0 votes
1 answer
167 views

Downcasting an implementation using an interface template

I'm implementing a generic interface that can bridge different implementations of some base class. The interface utility is written as follows: // InterfaceUtils.h // // Base object class class ...
Martin's user avatar
  • 141
0 votes
1 answer
244 views

Alternative to Pimpl

I am required to provide a solution to the following problem: A class is published as a library and made available to the world. It is designed in a way which does not use the pimpl approach. Two new ...
Mariah's user avatar
  • 101
0 votes
0 answers
64 views

How to call member functions of an IMPL from an injected strategy pattern

So I have been tasked with implementing a strategy pattern on an existing code base. The code below is a very simplified version of the code that I am using for demonstration purposes. I don't have a ...
FMunkee's user avatar
1 vote
2 answers
88 views

Passing the partially constructed object in pimpl

I have a class setup that I have converted to use pimpl, something like this: (outline only, I'm aware this doesn't compile) struct GAME { unique_ptr<GAME_IMPL> _impl; explicit GAME() :...
c z's user avatar
  • 7,826
2 votes
2 answers
471 views

In pimpl idiom, if without destructor, compiler would bring out error: can't delete an incomplete type

I am using visual studio on windows10 using C++. And I'm learning about pimpl idiom, what confuses me is that if without destructor of employee, compiler would bring out error: can't delete an ...
keepGoing's user avatar
2 votes
1 answer
365 views

Unique_ptr usage for pimpl - doesn't compile even though destructor is declared

I'm trying to use unique_ptr for a pimpl idiom. So I'm declaring a destructor inside the class so the unique_ptr deletion is not instantiated where the impl class is not defined, and then I define it ...
Asaf's user avatar
  • 4,327
0 votes
1 answer
193 views

move operation with pimpl idiom

In the following code I am attempting to use a move assignment within the PIMPL idiom, but the code does not compile. struct.hpp: #pragma once #include <memory> struct A { std::unique_ptr<...
francesco's user avatar
  • 7,252
0 votes
1 answer
288 views

Storing a class that uses the PIMPL idiom in a std::vector

I am writing an application that needs to store objects of a class that uses the PIMPL idiom in a std::vector. Because the class uses std::unique_ptr to store a pointer to it's implementation and std::...
tjwrona1992's user avatar
  • 8,624
3 votes
2 answers
183 views

Is there any reason not to use pimpl to implement move support in C++?

Obviously, pimpl is not strictly necessary, but if the class is designed the "normal" way, then, it seems that moving is not going to give you the full intended benefit: moving is supposed ...
allyourcode's user avatar
  • 21.9k
9 votes
1 answer
463 views

Is pimpl idiom better than using always unique_ptr as member variables?

In my workplace we have this convention: almost every class (with very few exceptions) is implemented with unique_ptrs, raw pointers or references as member variables. This is because of compilation ...
Dundo's user avatar
  • 714
-1 votes
1 answer
114 views

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 ...
yves84's user avatar
  • 1
1 vote
1 answer
293 views

How to give access to public members with Pimpl?

pimpl.h #include <memory> class MyClassImpl; class MyClass { void Foo(); struct MyStruct { int a; int b; } variable_struct; private: std::unique_ptr<...
Alexis's user avatar
  • 2,166
0 votes
1 answer
97 views

Finding a way to use PIMPL with external constant definitions for the size of an array inside the implementation

We have the following situation: We are using a processor which has defined sections inside its RAM, which must be used by a special implementation using the PIMPL-Principle. For example the private ...
NetoBF's user avatar
  • 127
1 vote
0 answers
154 views

PImpl with C++: Why does the code not work?

I've solved the problem by putting #include "stdafx.h" (this statement is missed in the original question, sorry for that) BEFORE #include "PImplTest.h" instead of AFTER it. But I'...
Irene's user avatar
  • 11
0 votes
1 answer
98 views

Pointer to Member Function Class Type

class Object { public: void mem_func(); } I want to be able to extract the type Object at compile time from a pointer to member function &Object::mem_func, but did not notice anything in <...
Matt Eding's user avatar
0 votes
2 answers
777 views

How to access private member of impl class from original class using PIMPL approach

I am using the PIMPL approach and would like to access a private member of the implementation class from the regular class. Is there any legitimate way to do this? In the below code, there are two ...
didjek's user avatar
  • 393
1 vote
0 answers
154 views

Hiding library dependencies using Pimpl doesn't seem to do anything

I am using PIMPL to hide implementation details of my library from the end user. Also want to capture all 3rd party dependencies of the library within itself; so that I would not need the end user to ...
Roy2511's user avatar
  • 938
0 votes
1 answer
97 views

c++ template argument deduction from another argument

I'm using pimpl pattern in my code, so for each class X, there will be a corresponding impl class XImpl Say we have A, AImpl, B, BImpl, C, CImpl, where A,B,C are similar class, and I would like to ...
Ziqi Liu's user avatar
  • 2,951
0 votes
0 answers
357 views

Modern Compilers Inlining Across Cpp Files and PImpl Idiom Overhead

I was taught that in general practice its best not to try to beat the compiler, at least until its proven to be stupid. So in general, and since its only used as a hint anyways, the inline tag has ...
Ryoku's user avatar
  • 397
0 votes
1 answer
359 views

Should I totally hide the internal class in my C++ header file when designing my SDK?

I am designing a SDK written in C++. I have a question: could or should I totally hide the internal class in my public C++ header file? The code snippets are like the following (in the header file ...
Bo Liu's user avatar
  • 23
-1 votes
1 answer
281 views

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 ...
Wör Du Schnaffzig's user avatar
3 votes
2 answers
245 views

Pimpl idiom and swap [duplicate]

I have several classes that are based on the PIMPL idiom (where a unique_ptr refers to the actual implementation struct). I haven't added a friend swap function (as described here) as, to my knowledge,...
Ben's user avatar
  • 1,529
0 votes
1 answer
137 views

PImpl idiom using std::unique_pointer with the implementation class in a seperate source file

I am writing a simple library to handle window creation across different platforms. To abstract away the platform specific code i want to use the PImpl idiom with a std::unique_ptr and provide a ...
Eric's user avatar
  • 1,193
3 votes
1 answer
270 views

How to avoid downcasting in this specific class hierarchy design?

I've got an assignment to create a sort of a multi-platform C++ GUI library. It wraps different GUI frameworks on different platforms. The library itself provides an interface via which the user ...
mrdecompilator's user avatar
2 votes
1 answer
72 views

How to check that PIMPL does not recompile client class

I try to understand the PIMPL idiom. I have several files, let's say "Implementation.cpp/Implementation.h" implement the PIMPL idiom: it contains a public interface and a private implementation. "...
Johan Diringer's user avatar

1
2 3 4 5
7