vendredi 24 novembre 2017

in C++11 I would like to get rid of the raw pointers in pimpl idiom

// I would like to get rid of the raw pointer (parent_) to the main class //in the pimpl idiom. What would be the best way to ag about it. Here is the //example:

//==============in "widget.h"
class Widget { 
public:
Widget() {};
…
private:
struct Impl;
std::unique_ptr<Impl> pImpl; 
};

//==== in .cpp 
#include "widget.h"
#include "gadget.h"
#include <string>
#include <vector>

struct Widget::Impl { 
Widget* parent_;
std::string name;
std::vector<double> data;
Gadget g1, g2, g3;

Impl (Widget* parent) : parent_ (parent) {}

};

Widget::Widget() 
: pImpl(std::make_unique<Impl>( this )) 
{} 

Aucun commentaire:

Enregistrer un commentaire