Boost logo

Boost :

Subject: Re: [boost] Pimpl Again?
From: Emil Dotchevski (emildotchevski_at_[hidden])
Date: 2016-05-31 15:03:33

On Mon, May 30, 2016 at 11:22 PM, Vladimir Batov <
Vladimir.Batov_at_[hidden]> wrote:

> On 2016-05-31 13:41, Emil Dotchevski wrote:
>> On Sun, May 29, 2016 at 10:47 PM, Vladimir Batov <
>> ...
>> Polymorphism -- the snippets I provided are sufficient, virtual function
>> calls work just fine. For example, in the CPP file you could define
>> do_something (see above declaration) like so:
>> void do_something( foo * p )
>> {
>> p->do_something(); //virtual
>> }
>> ...
> Indeed. You right... Once we take the methods out to be free-standing
> functions, there is nothing left of the interface/proxy class but
> shared_ptr<foo>... I have to admit it never occurred to me... :-) Not sure
> if I am ready to do things your way :-) but you are most certainly correct.
> Thank you.

Wow I must admit this surprises me, the resistance I usually get is much
stronger. :)

The problem from language design point of view is that in C++ the "dot
syntax" can only be used with member functions, but member functions have
access to the private data, which means that they must participate in the
type definitions (encapsulation), which means they can't be called without
the type being complete. The C++ solution to this problem is to use only
abstract types with no data members in header files, but that has virtual
function call overhead compared to the C-style approach.

It would have been useful for C++ to allow the declaration of non-friend
"member" functions outside of the type definition. This would require no
change in syntax.


Boost list run by bdawes at, gregod at, cpdaniel at, john at