220 7873 <CAFk2RUapU4MNTVoVe3F0DP+5C7M_AHPT6MQdHxfVDTH+3tsQfQ@mail.gmail.com> article
Path: news.gmane.org!not-for-mail
From: Ville Voutilainen <ville.voutilainen@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Limited inheritance for classes
Date: Wed, 20 Nov 2013 15:54:05 +0200
Lines: 58
Approved: news@gmane.org
Message-ID: <CAFk2RUapU4MNTVoVe3F0DP+5C7M_AHPT6MQdHxfVDTH+3tsQfQ@mail.gmail.com>
References: <f04aeac5-ab5a-4508-ae69-196f53e7a6f8@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
X-Trace: ger.gmane.org 1384955643 27711 80.91.229.3 (20 Nov 2013 13:54:03 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Wed, 20 Nov 2013 13:54:03 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBC5JHI7A7ALRB7X5WKKAKGQECYLS4ZI@isocpp.org Wed Nov 20 14:54:09 2013
Return-path: <std-proposals+bncBC5JHI7A7ALRB7X5WKKAKGQECYLS4ZI@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-pa0-f71.google.com ([209.85.220.71])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBC5JHI7A7ALRB7X5WKKAKGQECYLS4ZI@isocpp.org>)
	id 1Vj8EK-0007rf-4v
	for gclcip-std-proposals@m.gmane.org; Wed, 20 Nov 2013 14:54:08 +0100
Original-Received: by mail-pa0-f71.google.com with SMTP id kp14sf6953005pab.6
        for <gclcip-std-proposals@m.gmane.org>; Wed, 20 Nov 2013 05:54:06 -0800 (PST)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:mime-version:in-reply-to:references:date
         :message-id:subject:from:to:x-original-sender
         :x-original-authentication-results:reply-to:precedence:mailing-list
         :list-id:list-post:list-help:list-archive:list-subscribe
         :list-unsubscribe:content-type;
        bh=KBvYFM9PRog0+H3y369MNY3RFgjeR6McTNSVn3o6eRU=;
        b=fjxXHwkM+d67mo2vv+5OHlu1udBHXiULAQsv2sJd5vg8eD0uFof6lHfNuqSjCJ7Ovk
         VOb/kWDa4vKpPgqmnMQaEsyZ1a1akwdbKGCtaFfF3VGkz5WeT89iSkASsBPyQzMiI54C
         au7rT5keTzfTc8QeNz1Ig9HNAZa1SecMkt/HHlwpPJqke2PV6/zs8+sIRt4t9uiW9ksU
         4YvVZZOfAs75RIuQOde4EVAQVJaJTuPUoOC0S/0IlJtdmitYZQkBhDG7xyLoAl8rlqpL
         37tFYpZmapEe2LG0vEbxBJ4ms8Iee3gBwXqQop7+viCCL6SdGMY/bU+n73OISzpOVKg6
         PHUw==
X-Gm-Message-State: ALoCoQmBfTWpjdvl96/rnjd6fMP/t8+mQ0TTrgDn131nAdOD+mbVmLeBM6WU5OUfAlwbyAeDNTbb
X-Received: by 10.66.188.37 with SMTP id fx5mr235291pac.45.1384955646785;
        Wed, 20 Nov 2013 05:54:06 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.49.53.3 with SMTP id x3ls58962qeo.78.gmail; Wed, 20 Nov 2013
 05:54:05 -0800 (PST)
X-Received: by 10.229.127.74 with SMTP id f10mr1657914qcs.16.1384955645862;
        Wed, 20 Nov 2013 05:54:05 -0800 (PST)
Original-Received: from mail-qa0-x233.google.com (mail-qa0-x233.google.com [2607:f8b0:400d:c00::233])
        by mx.google.com with ESMTPS id o9si4294636qad.116.2013.11.20.05.54.05
        for <std-proposals@isocpp.org>
        (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
        Wed, 20 Nov 2013 05:54:05 -0800 (PST)
Received-SPF: pass (google.com: domain of ville.voutilainen@gmail.com designates 2607:f8b0:400d:c00::233 as permitted sender) client-ip=2607:f8b0:400d:c00::233;
Original-Received: by mail-qa0-f51.google.com with SMTP id o15so2885213qap.10
        for <std-proposals@isocpp.org>; Wed, 20 Nov 2013 05:54:05 -0800 (PST)
X-Received: by 10.224.66.5 with SMTP id l5mr1487703qai.31.1384955645516; Wed,
 20 Nov 2013 05:54:05 -0800 (PST)
Original-Received: by 10.224.68.3 with HTTP; Wed, 20 Nov 2013 05:54:05 -0800 (PST)
In-Reply-To: <f04aeac5-ab5a-4508-ae69-196f53e7a6f8@isocpp.org>
X-Original-Sender: ville.voutilainen@gmail.com
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of ville.voutilainen@gmail.com designates 2607:f8b0:400d:c00::233 as
 permitted sender) smtp.mail=ville.voutilainen@gmail.com;       dkim=pass
 header.i=@gmail.com;       dmarc=pass (p=NONE dis=NONE) header.from=gmail.com
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Google-Group-Id: 399137483710
List-Post: <http://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <http://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <http://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:7873
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/7873>

On 20 November 2013 15:50, Dmitry Leontiev <dm.leontiev7@gmail.com> wrote:
> Hello
>
> In my opinion, there must be a way tell compiler to not to expose parent
> class to child classes. Consider the following example:
>
> class EventHandler {
> protected:
>       virtual void function()=0;
> };
> class EventSource {
>     void RegisterEventHandler(EventHandler * ev);
> };
> //resides in some popular shared library
> class A : private EventHandler {
>     A(){
>        source1.RegisterEventHandler(this);
>     }
> private:
>       void function(){printf("a");}
> };
> //imlemented by a developer who is unaware of A internals
> class B : public A, private EventHandler {
>     B(){
>        source2.RegisterEventHandler(this);
>     }
> private:
>       void function(){printf("b");}
> };
>
> In this example, classes A and B register event handlers for different event
> sources upon creation.
> However, class B steals events from A by overriding function "function" in
> both EventHandlers.
> There must be a convinient way for "some popular shared library" developer
> to prevent overriding from child classes.
>
> for example
> class A : private static EventHandler { ... }


I can imagine at least two ways to do this with existing c++:
1) mark the overrides final in A
2) don't inherit EventHandler in A, inherit it in a subobject of A and
delegate the
overridden functions to non-virtual private functions of A

The latter is not as convenient as it could be without programmable reflection
dispatch, but it's not hugely inconvenient either. The former is rather easy.

-- 

--- 
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

.
