I think I see what you're saying now. We can do something like this:
class A{
virtual APrivate* private_data(){
return priv.get();
}
unique_ptr<APrivate> priv;
};
class B: public A{
virtual BPrivate* private_data(){
return static_cast<BPrivate*>(priv.get());
}
};
I don't see any advantage to this over a macro, unless you were
thinking of something else?
-Robert Middleton
On Sat, Nov 6, 2021 at 12:42 PM Thorsten Schöning <[email protected]> wrote:
>
> Guten Tag Robert Middleton,
> am Samstag, 6. November 2021 um 16:52 schrieben Sie:
>
> > Unfortunately not, for the reasons above. Since the parent class only
> > holds a single pointer to the private data, whatever data is stored
> > must be a subclass of the parent's private data. So we must cast it
> > to whatever class's private data that we are currently using.
>
> Understood, but does it really needs to be a macro? Why not use a
> method implementing the cast which can then be overridden by
> subclasses as necessary? Looks like a covariant return type to me,
> doesn't it?
>
> https://en.wikipedia.org/wiki/Covariant_return_type
>
> Mit freundlichen Grüßen
>
> Thorsten Schöning
>
> --
> AM-SoFT IT-Service - Bitstore Hameln GmbH
> Mitglied der Bitstore Gruppe - Ihr Full-Service-Dienstleister für IT und TK
>
> E-Mail: [email protected]
> Web: http://www.AM-SoFT.de/
>
> Tel: 05151- 9468- 0
> Tel: 05151- 9468-55
> Fax: 05151- 9468-88
> Mobil: 0178-8 9468-04
>
> AM-SoFT IT-Service - Bitstore Hameln GmbH, Brandenburger Str. 7c, 31789 Hameln
> AG Hannover HRB 221853 - Geschäftsführer: Janine Galonska
>
>
>
>