Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Trying to understand Pimpl

16 views
Skip to first unread message

Paul

unread,
Feb 24, 2017, 3:49:36 PM2/24/17
to
Here is some basic pimpl code below:
I don't understand why this is legal. It seems that class widget{..}
defines widget as a base class.
And then class widget is then redefined as a class privately inheriting
from impl.
Why isn't widget being illegally defined twice?
Also, can someone explain pimpl to me or direct me to a good explanation?

Thanks

Paul

class widget {
public:
widget();
~widget();
private:
class impl;
unique_ptr<impl> pimpl;
};

// in implementation file
class widget::impl {
// :::
};

widget::widget() : pimpl{ new impl{ /*...*/ } } { }
widget::~widget() { }

Ian Collins

unread,
Feb 24, 2017, 4:48:55 PM2/24/17
to
On 02/25/17 09:49 AM, Paul wrote:
> Here is some basic pimpl code below:
> I don't understand why this is legal. It seems that class widget{..}
> defines widget as a base class.

Where?

> And then class widget is then redefined as a class privately inheriting
> from impl.

Where?

> Why isn't widget being illegally defined twice?
> Also, can someone explain pimpl to me or direct me to a good explanation?

I think you need to explain where your conclusions (above) came from,
the code does not support them.

> class widget {

No base class...

> public:
> widget();
> ~widget();
> private:
> class impl;
> unique_ptr<impl> pimpl;

Contains a nested impl class, no inheritance.

--
Ian

Paul

unread,
Feb 24, 2017, 5:03:25 PM2/24/17
to
Ok. I get it now. Thanks.
I read it as class widget : private impl {//};
I'm nervous about an upcoming job interview, and
it's affecting my thinking.

Paul
0 new messages