|
Boost : |
From: Martin Bonner (martin.bonner_at_[hidden])
Date: 2006-04-07 11:35:27
----Original Message----
From: boost-bounces_at_[hidden]
[mailto:boost-bounces_at_[hidden]] On Behalf Of Sebastian Redl
Sent: 07 April 2006 16:14 To: boost_at_[hidden]
Subject: Re: [boost] Sealed C++ class.
> Vladislav Lazarenko wrote:
>
>> template <typename T>
>> class sealed : virtual private sealed_::sealed_impl<sealed, T>
>>
>>
> Interesting idea. Any particular reason why this inheritance is
> virtual?
> sealed_impl being a template should be rare to duplicate as a base,
> and
> having no data members or virtual functions, it should be irrelevant
> even if it was duplicated. On the other hand, you introduce the
> troubles
> that come with virtual inheritance.
>
> Sebastian Redl
If I write
class Broken : public UniquePerson {};
Then the constructor of Broken has to invoke the constructor of
sealed_impl. However the constructor is private, so it can't. The
result is a compilation error.
The problem is the code:
template <typename T1, typename T2>
class sealed_impl
{
friend typename T1;
friend typename T2;
...
7.1.5.3 p2 says "[Note: this implies that, within a class template with
a template type-parameter T, the declaration friend class T; is
ill-formed.]"
In other words, you can't do that :-(
-- Martin Bonner Martin.Bonner_at_[hidden] Pi Technology, Milton Hall, Ely Road, Milton, Cambridge, CB4 6WZ, ENGLAND Tel: +44 (0)1223 203894
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk