327 questions
2
votes
1
answer
112
views
Hide implementation similar to pimpl without heap allocafion
I am trying to hide some implementation behind an opaque data type. Normally, pimpl would be the preferred pattern, but it requires heap allocation which is not desirable in this context (embedded, ...
1
vote
0
answers
103
views
Can Memory Be Contiguous With PIMPL Idiom? [duplicate]
Foo.h
class Foo
{
private:
int a;
bool b;
float c;
};
I have a class like the one above that is used when interacting with an API that itself interacts with the GPU.
To reduce CPU->GPU ...
2
votes
2
answers
145
views
unordered_map of class following pImpl idiom using unique_ptr
Here is a simplified code: https://godbolt.org/z/EnE76xMrP
The pImpl will contain a mutex member which make the pImpl neither copyable nor movable. But the Foo class has unique_ptr of pImpl as member ...
0
votes
0
answers
213
views
Pimpl idiom without pointer indirection?
I'm developing a C++ API and I want to hide private implementation details from the public interface. Currently, I'm employing the Pimpl idiom for this purpose. However, I'm also mindful of minimizing ...
3
votes
0
answers
122
views
In pimpl design using std::unique_ptr, if dtor is put in implementation file BEFORE Impl type definition, why is it compiling ok?
First, I know that in pimpl design with std::unique_ptr, the destructor of the client class cannot be inline and needs to be implemented in the implementation file because the unique_ptr destructor ...
5
votes
2
answers
694
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 ...
0
votes
0
answers
63
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 ...
3
votes
0
answers
263
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();
...
0
votes
0
answers
202
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:
...
3
votes
2
answers
403
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 ...
5
votes
1
answer
342
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 ...
0
votes
1
answer
121
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 ...
0
votes
0
answers
116
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 ...
0
votes
0
answers
41
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 ...
3
votes
0
answers
326
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 ...
17
votes
1
answer
678
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 ...
2
votes
1
answer
1k
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 ...
-1
votes
1
answer
401
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 ...
0
votes
1
answer
393
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 ...
1
vote
2
answers
182
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() :...
2
votes
1
answer
694
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 ...
0
votes
1
answer
480
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::...
11
votes
1
answer
899
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 ...
1
vote
1
answer
442
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<...
1
vote
0
answers
207
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'...