pimpl-idiom

The pImpl idiom and Testability

戏子无情 提交于 2021-02-17 08:58:00
问题 The pImpl idiom in c++ aims to hide the implementation details (=private members) of a class from the users of that class. However it also hides some of the dependencies of that class which is usually regarded bad from a testing point of view. For example if class A hides its implementation details in Class AImpl which is only accessible from A.cpp and AImpl depends on a lot of other classes, it becomes very difficult to unit test class A since the testing framework has no access to the

The pImpl idiom and Testability

房东的猫 提交于 2021-02-17 08:57:06
问题 The pImpl idiom in c++ aims to hide the implementation details (=private members) of a class from the users of that class. However it also hides some of the dependencies of that class which is usually regarded bad from a testing point of view. For example if class A hides its implementation details in Class AImpl which is only accessible from A.cpp and AImpl depends on a lot of other classes, it becomes very difficult to unit test class A since the testing framework has no access to the

Linker error while implementing pimpl idiom

不羁岁月 提交于 2021-02-11 13:10:44
问题 Edited to provider a little more clarity. Apologies for confusing everyone. This is under Windows. I have a static library that implements a class using the pimpl idiom. The pimpl header is not only used by the consuming code but it also links against the static library. Yet, when I compile the consuming code (.exe), the linker complains about unresolved externals on the implementation class that the pimpl header supposedly hides. How can this be possible? // Foo.lib // Foo.h class FooImpl;

Linker error while implementing pimpl idiom

穿精又带淫゛_ 提交于 2021-02-11 13:07:56
问题 Edited to provider a little more clarity. Apologies for confusing everyone. This is under Windows. I have a static library that implements a class using the pimpl idiom. The pimpl header is not only used by the consuming code but it also links against the static library. Yet, when I compile the consuming code (.exe), the linker complains about unresolved externals on the implementation class that the pimpl header supposedly hides. How can this be possible? // Foo.lib // Foo.h class FooImpl;

How to avoid downcasting in this specific class hierarchy design?

让人想犯罪 __ 提交于 2020-05-13 14:09:57
问题 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 communicates uniformly regardless of the platform he's using. I need to design this interface and underlying communication with the framework properly. What I've tried is: Pimpl idiom - this solution was chosen at first because of its advantages - binary compatibility, cutting the dependency tree to

What are the rules for noexcept on default defined move constructors?

我只是一个虾纸丫 提交于 2020-02-21 08:25:52
问题 Especially in connection with std::vector it is important that types are noexcept movable when possible. So when declaring a move constructor = default like in struct Object1 { Object1(Object1 &&other) = default; }; std::is_nothrow_move_constructible<Object1>::value will be true as every member (0 here) of Object1 is nothrow-move-constructible, which is answered here. Yet what happens if the move copy constructor is only declared and then later = default defined like in the following code?

Using pimpl with Templated Class and explicitly instantiated templates

三世轮回 提交于 2020-01-25 06:35:26
问题 How do I use pimpl for a templated class, when I explicitly instantiate the templates? All I need is an example code. What I have tried is: // MyTemplatedClass.h template< class T > class MyTemplatedClass { private: class Impl; Impl* _pimpl; public: void PublicMethod(); } Here my implementation goes: // MyTemplatedClass.cpp template< class T > class MyTemplatedClass<T>::Impl { public: void PublicMethod(); } template <class T> void MyTemplatedClass<T>::Impl::PublicMethod() { ... } Forwarding

Spotting compilation-time bottlenecks in order to compilation firewall efficiently [closed]

我与影子孤独终老i 提交于 2020-01-04 05:06:05
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 5 years ago . I have this big C++ boostified project that takes ages to build so i'm trying to set up compilation firewalls. Now I could sprinkle pimpls or pure interfaces following my intuition but that doesn't seem very efficient... usually if i wanted to optimize a piece of code, I

Pimpl Idiom with template member function

佐手、 提交于 2019-12-24 09:40:04
问题 I want to use the Pimpl Idiom but I'm having a problem that one of the member functions is template function so it has to be implemented in a header file. For example this below works fine of course //Foo.h class Foo{ struct Impl; Impl* ptr; public: Foo(); void bar(int); ~Foo(); }; //Foo.cpp struct Foo::Impl{ void bar(int i){ std::cout << "i = " << i << std::endl; } }; Foo::Foo() : ptr{new Impl}{} void Foo::bar(int i){ ptr->bar(i); } Foo::~Foo(){ delete ptr; } but is there any way to