pimpl-idiom

Viewing a pimpl from DLL in debugger

大憨熊 提交于 2019-12-06 23:24:03
问题 I am using the pimpl idiom to hide the implementation details of an interface so that I can have some measure of ABI protection. I'm not that well versed on the ins and outs of MS...using Linux for most of my development career. I'm unable to view the insides of the pimpl from the debugger inspection window. My types expand only so far as the raw pointer to impl (it uses a smart pointer). I've tried exporting the symbols, but that doesn't seem to work. I suppose the symbols I'm actually

Invalid use of incomplete type on qt private class

北慕城南 提交于 2019-12-06 16:14:53
I want to use the d-pointer in a derived class with the help of Q_D macro. Here is my parent class: class DIGIKAM_EXPORT GraphicsDImgView : public QGraphicsView { Q_OBJECT public: class GraphicsDImgViewPrivate; protected: GraphicsDImgViewPrivate* const d_ptr; protected: Q_DECLARE_PRIVATE(GraphicsDImgView) }; and my GraphicsDImgViewPrivate class: class GraphicsDImgView::GraphicsDImgViewPrivate { public: GraphicsDImgViewPrivate() { scene = 0; item = 0; layout = 0; cornerButton = 0; panIconPopup = 0; movingInProgress = false; showText = true; } QGraphicsScene* scene; GraphicsDImgItem* item;

Inner class depending on a template argument

风流意气都作罢 提交于 2019-12-06 13:37:37
问题 Consider next example : #include <iostream> #include <typeinfo> template< int N, typename T > struct B { struct C; }; template< typename T > struct B< 0, T >::C { typedef T type; }; template< int N, typename T > struct B< N, T >::C { typedef T type[N]; }; int main() { std::cout<<"n=0 type = " << typeid( B< 0, float >::C::type ).name() << std::endl; std::cout<<"n=5 type = " << typeid( B< 5, float >::C::type ).name() << std::endl; } When compiled using g++ (version 4.3.0) g++ dfg.cpp -ansi

C++ Pimpl Idiom Incomplete Type using std::unique_ptr

风流意气都作罢 提交于 2019-12-05 21:24:51
I apologize for the large amount of code required to demonstrate the issue. I am having a problem using the pimpl idiom with std::unique_ptr. Specifically the problem seems to occur when one class (which has pimpl'ed implementation) is used as member data in another composite class with pimpl'ed implementation. Most of the answers I've been able to find deal with a lack of explicit destructor declaration , but as you can see here, I have declared and defined the destructors. What is wrong with this code, and can it be modified to compile without changing the design? Note: the error seems to

Pimpl-idiom in the D programming language

守給你的承諾、 提交于 2019-12-05 12:48:35
D has a fantastic module system which reduces compilation times dramatically compared to C++. According to the documentation D still provides opaque structs and unions in order to enable the pimpl idiom. My question is: How can I declare a nested struct (or union) in one module and define it in another one? What is the syntax for that? In C++ the header would look like this struct S { ... struct Impl; Impl * p; }; and the implementation file (cpp-file) would use some interesting-looking :: -syntax like this: #include "header.h" struct S::Impl { ... }; How do I implement the same in D? D (DMD,

Must provide destructor in the PIMPL

妖精的绣舞 提交于 2019-12-05 08:27:17
// main_pimpl_sample.cpp #include "pimpl_sample.hpp" using namespace std; int main() { pimpl_sample p; return 0; } // pimpl_sample.cpp #include "pimpl_sample.hpp" struct pimpl_sample::impl { }; pimpl_sample::pimpl_sample() : pimpl_(new impl) { } // pimpl_sample::~pimpl_sample() // cause problem if missed // {} // pimpl_sample.hpp #if !defined (PIMPL_SAMPLE) #define PIMPL_SAMPLE #include <boost/scoped_ptr.hpp> class pimpl_sample { struct impl; boost::scoped_ptr<impl> pimpl_; public: pimpl_sample(); //~pimpl_sample(); cause problem if missed void do_something(); }; #endif ~/Documents/C++/boost $

Is there a way to combine the benefits of compiler firewalls (Pimpl) and default-copyability?

不羁的心 提交于 2019-12-05 00:11:16
问题 Suppose I have a class with a private member, which is an implementation detail that clients of the class don't care about. This class is a value type and we want it to be copyable, eg #include <boost/bimap.hpp> // some header that pulls in many other files class MyClass { public: MyClass() {} ... private: boost::bimap<Key,Value> table; }; Now every client of MyClass is forced to pull in lots of boost headers it doesn't really need, increasing build times. However, the class is at least

Pimpl idiom using shared_ptr working with incomplete types

风格不统一 提交于 2019-12-04 23:49:26
问题 I'm reading Effective Modern C++ by Scott Meyers and he's discussing the use of the pimpl idiom and pointing to the implementation class with unique_ptr , but there is an issue of special member functions (such as destructors) requiring the type to be complete. This is because unique_ptr 's default deleter statically asserts whether the type to be deleted is complete, before delete p is used. So any special member functions of the class must be defined in the implementation file (rather than

Inner class depending on a template argument

会有一股神秘感。 提交于 2019-12-04 18:09:29
Consider next example : #include <iostream> #include <typeinfo> template< int N, typename T > struct B { struct C; }; template< typename T > struct B< 0, T >::C { typedef T type; }; template< int N, typename T > struct B< N, T >::C { typedef T type[N]; }; int main() { std::cout<<"n=0 type = " << typeid( B< 0, float >::C::type ).name() << std::endl; std::cout<<"n=5 type = " << typeid( B< 5, float >::C::type ).name() << std::endl; } When compiled using g++ (version 4.3.0) g++ dfg.cpp -ansi -pedantic -Wall the compile error is : dfg.cpp:13: error: qualified name does not name a class before ‘{’

C++: Creating a shared object rather than a shared pointer to an object

半腔热情 提交于 2019-12-04 03:44:01
问题 boost::shared_ptr really bothers me. Certainly, I understand the utility of such a thing, but I wish that I could use the shared_ptr<A> as an A* . Consider the following code class A { public: A() {} A(int x) {mX = x;} virtual void setX(int x) {mX = x;} virtual int getX() const {return mX;} private: int mX; }; class HelpfulContainer { public: //Don't worry, I'll manager the memory from here. void eventHorizon(A*& a) { cout << "It's too late to save it now!" << endl; delete a; a = NULL; } };