220 39188 <ebc202be-4def-427a-95ff-7239efb4b89f@isocpp.org> article
Path: news.gmane.org!.POSTED!not-for-mail
From: cppljevans@gmail.com
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: new feature: declare data that replaces the
 previous one, or similar situation....
Date: Wed, 18 Jul 2018 03:04:33 -0700 (PDT)
Lines: 619
Approved: news@gmane.org
Message-ID: <ebc202be-4def-427a-95ff-7239efb4b89f@isocpp.org>
References: <adc40bab-d824-440b-99b9-dab0ad6bd482@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_11541_1987043502.1531908273240"
X-Trace: blaine.gmane.org 1531908149 28177 195.159.176.226 (18 Jul 2018 10:02:29 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Wed, 18 Jul 2018 10:02:29 +0000 (UTC)
Cc: rmbeer2@gmail.com
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBDAYTI72VMGRBMVBXTNAKGQELBRDJ7Y@isocpp.org Wed Jul 18 12:02:25 2018
Return-path: <std-proposals+bncBDAYTI72VMGRBMVBXTNAKGQELBRDJ7Y@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-yw0-f200.google.com ([209.85.161.200])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBDAYTI72VMGRBMVBXTNAKGQELBRDJ7Y@isocpp.org>)
	id 1ffjHs-0007De-TH
	for gclcip-std-proposals@m.gmane.org; Wed, 18 Jul 2018 12:02:25 +0200
Original-Received: by mail-yw0-f200.google.com with SMTP id i77-v6sf2157660ywe.19
        for <gclcip-std-proposals@m.gmane.org>; Wed, 18 Jul 2018 03:04:36 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=date:from:to:cc:message-id:in-reply-to:references:subject
         :mime-version:x-original-sender:reply-to:precedence:mailing-list
         :list-id:list-post:list-help:list-archive:list-subscribe
         :list-unsubscribe;
        bh=gZlNzbefEQscgpetg0iNqlY3y0I/dsHVmaAHFyszC5s=;
        b=CJ6RKklj7PAbblQNNkZIF3OlN0wQ04GSxlgZDqkeCmLDcTOf27XX+U5FyZ/Zd9vNSO
         xzmclOWbtD8k1MnTXDG5zG2X02XFTqt6e5bu1ciSQ3RJHi7V0qWof9pgBIeGwn7ZJdOj
         0SdFLTAZ2WlbguJCQbsIT3AQa/r7OTXvkV7WGWnpEDZpWl58fFX0YcI0Eo5kNc420Qs6
         FnNBr+yaDUMOoOEwXRtO9YMa1Ipc21eKRk6QkvwmFXewrsu5dNC8kdYkHFACXkFK6xZY
         3bgYLHGl9pTvgHOKC1+9h2YLfdBCzaw+bTnqebMhWdkFWZRKj2IeYFHRPAfWyYmwkdtI
         r1XQ==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=date:from:to:cc:message-id:in-reply-to:references:subject
         :mime-version:x-original-sender:reply-to:precedence:mailing-list
         :list-id:list-post:list-help:list-archive:list-subscribe
         :list-unsubscribe;
        bh=gZlNzbefEQscgpetg0iNqlY3y0I/dsHVmaAHFyszC5s=;
        b=c/SFm+c6SMlUOicO6VcR/TS08+XLnTG2QzBFGVxNITavseSW6DRiEsRIrPBzeMgL/P
         Ef1+fsnXwm5suHC0ZTLRiBd6GMmeLCh2ymKfdJXTnTx70Endz7axim0j16Pkjpb4Ns8C
         3Ho83Hzx3jNnMED1mM+gpXR+S6XYgTXq4Irqg3WgcaYgHI/Ygq29gYZ4bC3RLGPEghda
         XnEaykgFK6SmIVL+GwmZ4Lwu4HE8Td5E+W32rjpMsKNAbVZXqJWTGgzqJfLA2fZsAMqH
         qYoMiwK5vAEm9ZhHWVIV/auUPEwScN9lK+px4ehs174Ac7fwGpQxg3HFnCmlUI05tiAo
         AaeA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:date:from:to:cc:message-id:in-reply-to
         :references:subject:mime-version:x-original-sender:reply-to
         :precedence:mailing-list:list-id:x-spam-checked-in-group:list-post
         :list-help:list-archive:list-subscribe:list-unsubscribe;
        bh=gZlNzbefEQscgpetg0iNqlY3y0I/dsHVmaAHFyszC5s=;
        b=MAqWWD6mnhCHl86JAhWWRjghUgcK6gjWG0P8SGtUKoJDUxO5n/bVlL6kGU3w8Dlurr
         F1nNO5pYugRWxRbyz7t4hSg8yWVMz1kyx2hxjz/A0pRpkTVslKAghN9w6iNoOIzgE7vl
         ti72Su+xeQ9I63xKqVbvdXfMAI9N+czU7zhR/ro00Uz0qL8LQZMAxFj+n/IZ3WuzlSsr
         QejZZlpsKDWj+HV0O9HoPI/iMWzpqoxmJaRl/1rfJ0PhxGNmH+D2p1F4wGKoiDCIFdr3
         rEN0ftMpTx9ND9AWM78KKm2zP1LEMc6P9SayaNpfHXfvcEOo+rxoYs1kyVeEbrf1Ugxc
         o6lQ==
X-Gm-Message-State: AOUpUlH8+m1QSlH6dlwVk5nNAUKJ122moZ8Ey3WuWtnVthfeNqGoeaqp
	pRThEaerAmPm55VwKvH7IoHBnQ==
X-Google-Smtp-Source: AAOMgpckufkfwDrRBYEYNzFsMOnvmVGW8DjlxQk3fcPL8zUt8bFRw+QAzd8lnwzZhuRmFRU6TeqSkw==
X-Received: by 2002:a25:bc89:: with SMTP id e9-v6mr1524307ybk.70.1531908275573;
        Wed, 18 Jul 2018 03:04:35 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 2002:a25:2548:: with SMTP id l69-v6ls594073ybl.12.gmail; Wed, 18
 Jul 2018 03:04:34 -0700 (PDT)
X-Received: by 2002:a5b:349:: with SMTP id q9-v6mr605108ybp.7.1531908274070;
        Wed, 18 Jul 2018 03:04:34 -0700 (PDT)
In-Reply-To: <adc40bab-d824-440b-99b9-dab0ad6bd482@isocpp.org>
X-Original-Sender: cppljevans@gmail.com
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Spam-Checked-In-Group: std-proposals@isocpp.org
X-Google-Group-Id: 399137483710
List-Post: <https://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <https://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <https://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>,
 <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:39188
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/39188>

------=_Part_11541_1987043502.1531908273240
Content-Type: multipart/alternative; 
	boundary="----=_Part_11542_1573015084.1531908273240"

------=_Part_11542_1573015084.1531908273240
Content-Type: text/plain; charset="UTF-8"



On Monday, June 11, 2018 at 7:17:54 PM UTC-5, rmb...@gmail.com wrote:
>
> We have 2 classes that contain different data sets, one needs to use the 
> functions and variables of another class, so it is included as a member 
> pointing to the other class:
>
>    member
> A -------> B
>
> Code:
> ---------------------------------------
>
> class A {
> public:
>     A(int z_) : z(z_) {    }
>     int z;
> };
>
> class B {
> public:
>     B() : a(1) { }
>     void f2() {
>         std::cout << "A:" << a.z << std::endl;
>     }
>     A a;
> };
>
> ---------------------------------------
>
> Then you need to create an inheritance for each class, since you need to 
> cover a new interface layer. Let's call C and D, where C uses the base 
> class A and D uses the base class B.
>
>    member
> A ---------> B
> |            |
> |inheritance | inheritance
> |            |
> v  member    v
> C ---------> D
>
> Code:
> ---------------------------------------
>
> class A {
> public:
>     A(int z_) : z(z_) {    }
>     int z;
> };
> class C: public A {
> public:
>     C(int y_) : y(y_), A(y_) {    }
>     long y;
> };
>
> class B {
> public:
>     B() : a(1) { }
>     void f2() {
>         std::cout << "A:" << a.z << std::endl;
>     }
>     A a;
> };
> class D: public B {
> public:
>     B() : a(3) { }
>     void f2() {
>         std::cout << "A:" << a.z << std::endl;
>     }
>     C a;
> };
>
> ---------------------------------------
>
> Here where the problems appear, if you create B you can access the data of 
> A with the functions of B. But if you create D, you access the data of C+A 
> with the functions of D and C, but as soon as you call the functions 
> inherited from B, B can only access the data of A that are totally in 
> disuse, that is, create an instance in D generates in memory a variable "a" 
> with C+A, and also a variable "a" with A , being in class D a C+A, A, where 
> the last A is not used, only C+A, in A it ends up using when the functions 
> of B. are called.
>   It is only possible to create a new virtual type function as the only 
> case to access only C+A, but this generates junk code and in memory it 
> reserves A as garbage:
>
> Code:
> ---------------------------------------
> #include <iostream>
>
> class A {
> public:
>     A(int z_) : z(z_) {    }
>     int z;
> };
>
> class C: public A {
> public:
>     C(int z_) : A(z_) {    }
> };
>
> class B {
> public:
>     B() : a(1) { }
>     void f2() {
>         std::cout << "A:" << get_C_a().z << std::endl;
>     }
>     virtual A const& get_C_a() { return a; }
>     A a; // Use only from B
> };
>
> class D : public B {
> public:
>     D() : a(3) { }
>     void f2(){
>         std::cout << "C+A:" << a.z << std::endl;
>         B::f2();
>     }
>     C a; // Use C+A only from D
>     A const& get_C_a() override { return a; }
> };
>
> int main() {
>     B b; D d;
>     b.f2(); d.f2();
>     return 0;
> }
>
> /* OUTPUT:
> A:1
> C+A:3
> A:3
> */
>
> ---------------------------------------
>
> This would be the best option, but not the ideal one. Ideally, "C a;" of D 
> replace "A a;" of B, in this way D only uses C+A from "C a;" and B only 
> uses A from "A a;"
>
> This is my proposal, a keyword like 'virtual' (or can be any other) in the 
> variable of the same name that is replaced by the variable definition of 
> the base class.
>
> Por ejemplo:
> Code:
> ---------------------------------------
> #include <iostream>
>
> class A {
> public:
>     A(int z_) : z(z_) {    }
>     int z;
> };
>
> class C: public A {
> public:
>     C(int z_) : A(z_) {    }
> };
>
> class B {
> public:
>     B() : a(1) { }
>     void f2() {
>         std::cout << "A:" << a.z << std::endl;
>     }
>     virtual A a; // Use A only from B
> };
>
> class D : public B {
> public:
>     D() : a(3) { }
>     void f2(){
>         std::cout << "C+A:" << a.z << std::endl;
>         B::f2();
>     }
>     virtual C a; // Use C+A only from D
> };
>
> int main() {
>     B b; D d;
>     b.f2(); d.f2();
>     return 0;
> }
>
> /* OUTPUT:
> A:1
> C+A:3
> A:3
> */
>
> ---------------------------------------
>
> well this might not be possible, since compiled the code, the binary code 
> uses the data from an expected position in the variables within the 
> classes, so removing it from the list could alter the size and position of 
> the variables. On the other hand it would be possible, since reserving 
> memory from A or from C as C+A, generates a group of variables reserved in 
> memories for each class even if it is C+A and calls functions of A which 
> omits C of C+A Just to have A in view, this could be an advantage.
> I suggest some other option to simulate a replacement of variable A by C.
> If there is a better method that fulfills the same purpose without 
> breaking with the basic structure proposed here then much better.
>
>
> ================================================================================
>
> Tenemos 2 clases que contienen distintos conjuntos de datos, uno necesita 
> usar las funciones y variables de otra clase, por lo que se incluye como 
> miembro apuntando a la otra clase:
>
>    member
> A -------> B
>
> Code:
> ---------------------------------------
>
> class A {
> public:
>     A(int z_) : z(z_) {    }
>     int z;
> };
>
> class B {
> public:
>     B() : a(1) { }
>     void f2() {
>         std::cout << "A:" << a.z << std::endl;
>     }
>     A a;
> };
>
> ---------------------------------------
>
> Luego se necesita crear una herencia para cada clase, ya que necesita 
> cubrir una nueva capa de interfaz. Llamemos C y D, donde C usa la clase 
> base A y D usa la clase base B.
>
>    member
> A ---------> B
> |            |
> |inheritance | inheritance
> |            |
> v  member    v
> C ---------> D
>
> Code:
> ---------------------------------------
>
> class A {
> public:
>     A(int z_) : z(z_) {    }
>     int z;
> };
> class C: public A {
> public:
>     C(int y_) : y(y_), A(y_) {    }
>     long y;
> };
>
> class B {
> public:
>     B() : a(1) { }
>     void f2() {
>         std::cout << "A:" << a.z << std::endl;
>     }
>     A a;
> };
> class D: public B {
> public:
>     B() : a(3) { }
>     void f2() {
>         std::cout << "A:" << a.z << std::endl;
>     }
>     C a;
> };
>
> ---------------------------------------
>
>   Aqui donde aparecen los problemas, si creas B puedes acceder a los datos 
> de A con las funciones de B. Pero si creas D, accedes a los datos de C+A 
> con las funciones de D y C, pero tan pronto llamas a las funciones 
> heredadas de B, B solo puede acceder a los datos de A que estan totalmente 
> en desuso, es decir, crear una instancia en D genera en la memoria una 
> variable "a" con C+A, y tambien una variable "a" con A, siendo en la clase 
> D un C+A,A , donde la ultima A no se usa, solo C+A , en A se termina usando 
> cuando se llama a las funciones de B.
>     Solo es posible crear una nueva funcion tipo virtual como unico caso 
> para acceder solamente a C+A, pero esto genera codigo basura y en la 
> memoria se reserva A como basura:
>
> Code:
> ---------------------------------------
> #include <iostream>
>
> class A {
> public:
>     A(int z_) : z(z_) {    }
>     int z;
> };
>
> class C: public A {
> public:
>     C(int z_) : A(z_) {    }
> };
>
> class B {
> public:
>     B() : a(1) { }
>     void f2() {
>         std::cout << "A:" << get_C_a().z << std::endl;
>     }
>     virtual A const& get_C_a() { return a; }
>     A a; // Use only from B
> };
>
> class D : public B {
> public:
>     D() : a(3) { }
>     void f2(){
>         std::cout << "C+A:" << a.z << std::endl;
>         B::f2();
>     }
>     C a; // Use C+A only from D
>     A const& get_C_a() override { return a; }
> };
>
> int main() {
>     B b; D d;
>     b.f2(); d.f2();
>     return 0;
> }
>
> /* OUTPUT:
> A:1
> C+A:3
> A:3
> */
>
> ---------------------------------------
>
> Esta seria la mejor opcion, pero no la ideal. Lo ideal es que "C a;" de D 
> remplace a "A a;" de B, de esta forma D solo usa C+A de "C a;" y B solo usa 
> A de "A a;"
>
> Esta es mi propuesta, una palabra clave como 'virtual' (o puede ser 
> cualquier otra) en la variable del mismo nombre que se remplace a la 
> definicion de variable de la clase base.
>
> Por ejemplo:
> Code:
> ---------------------------------------
> #include <iostream>
>
> class A {
> public:
>     A(int z_) : z(z_) {    }
>     int z;
> };
>
> class C: public A {
> public:
>     C(int z_) : A(z_) {    }
> };
>
> class B {
> public:
>     B() : a(1) { }
>     void f2() {
>         std::cout << "A:" << a.z << std::endl;
>     }
>     virtual A a; // Use A only from B
> };
>
> class D : public B {
> public:
>     D() : a(3) { }
>     void f2(){
>         std::cout << "C+A:" << a.z << std::endl;
>         B::f2();
>     }
>     virtual C a; // Use C+A only from D
> };
>
>
>
[snip]
This problem sounds similar to the "dual inheritance
hierarchy" problem that this reference:

https://pdfs.semanticscholar.org/f403/361d9ef3dac96463787b852b605a918bc4fe.pdf

addresses.  For example, the A and B classes above
correspond to the B1 and B2 classes in Figure 3 of the above
reference, and the C and D classes above correspond to the
D1 and D2 classes in Figure 3 of the above reference.

Is that how it seems to you?

-regards,
Larry

-- 
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.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/ebc202be-4def-427a-95ff-7239efb4b89f%40isocpp.org.

------=_Part_11542_1573015084.1531908273240
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><br>On Monday, June 11, 2018 at 7:17:54 PM UTC-5, rmb.=
...@gmail.com wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;mar=
gin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D=
"ltr">We have 2 classes that contain different data sets, one needs to use =
the functions and variables of another class, so it is included as a member=
 pointing to the other class:<br><br>=C2=A0=C2=A0 member<br>A -------&gt; B=
<br><br>Code:<br>------------------------------<wbr>---------<br><br>class =
A {<br>public:<br>=C2=A0=C2=A0 =C2=A0A(int z_) : z(z_) {=C2=A0=C2=A0 =C2=A0=
}<br>=C2=A0=C2=A0 =C2=A0int z;<br>};<br><br>class B {<br>public:<br>=C2=A0=
=C2=A0 =C2=A0B() : a(1) { }<br>=C2=A0=C2=A0 =C2=A0void f2() {<br>=C2=A0=C2=
=A0 =C2=A0=C2=A0=C2=A0 =C2=A0std::cout &lt;&lt; &quot;A:&quot; &lt;&lt; a.z=
 &lt;&lt; std::endl;<br>=C2=A0=C2=A0 =C2=A0}<br>=C2=A0=C2=A0 =C2=A0A a;<br>=
};<br><br>------------------------------<wbr>---------<br><br>Then you need=
 to create an inheritance for each class, since you need to cover a new int=
erface layer. Let&#39;s call C and D, where C uses the base class A and D u=
ses the base class B.<br><br>=C2=A0=C2=A0 member<br>A ---------&gt; B<br>|=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 |<br>|in=
heritance | inheritance<br>|=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0 |<br>v=C2=A0 member=C2=A0=C2=A0=C2=A0 v<br>C --------=
-&gt; D<br><br>Code:<br>------------------------------<wbr>---------<br><br=
>class A {<br>public:<br>=C2=A0=C2=A0 =C2=A0A(int z_) : z(z_) {=C2=A0=C2=A0=
 =C2=A0}<br>=C2=A0=C2=A0 =C2=A0int z;<br>};<br>class C: public A {<br>publi=
c:<br>=C2=A0=C2=A0 =C2=A0C(int y_) : y(y_), A(y_) {=C2=A0=C2=A0 =C2=A0}<br>=
=C2=A0=C2=A0 =C2=A0long y;<br>};<br><br>class B {<br>public:<br>=C2=A0=C2=
=A0 =C2=A0B() : a(1) { }<br>=C2=A0=C2=A0 =C2=A0void f2() {<br>=C2=A0=C2=A0 =
=C2=A0=C2=A0=C2=A0 =C2=A0std::cout &lt;&lt; &quot;A:&quot; &lt;&lt; a.z &lt=
;&lt; std::endl;<br>=C2=A0=C2=A0 =C2=A0}<br>=C2=A0=C2=A0 =C2=A0A a;<br>};<b=
r>class D: public B {<br>public:<br>=C2=A0=C2=A0 =C2=A0B() : a(3) { }<br>=
=C2=A0=C2=A0 =C2=A0void f2() {<br>=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0std=
::cout &lt;&lt; &quot;A:&quot; &lt;&lt; a.z &lt;&lt; std::endl;<br>=C2=A0=
=C2=A0 =C2=A0}<br>=C2=A0=C2=A0 =C2=A0C a;<br>};<br><br>--------------------=
----------<wbr>---------<br><br>Here where the problems appear, if you crea=
te B you can access the data of A with the functions of B. But if you creat=
e D, you access the data of C+A with the functions of D and C, but as soon =
as you call the functions inherited from B, B can only access the data of A=
 that are totally in disuse, that is, create an instance in D generates in =
memory a variable &quot;a&quot; with C+A, and also a variable &quot;a&quot;=
 with A , being in class D a C+A, A, where the last A is not used, only C+A=
, in A it ends up using when the functions of B. are called.<br>=C2=A0 It i=
s only possible to create a new virtual type function as the only case to a=
ccess only C+A, but this generates junk code and in memory it reserves A as=
 garbage:<br><br>Code:<br>------------------------------<wbr>---------<br>#=
include &lt;iostream&gt;<br><br>class A {<br>public:<br>=C2=A0=C2=A0 =C2=A0=
A(int z_) : z(z_) {=C2=A0=C2=A0 =C2=A0}<br>=C2=A0=C2=A0 =C2=A0int z;<br>};<=
br><br>class C: public A {<br>public:<br>=C2=A0=C2=A0 =C2=A0C(int z_) : A(z=
_) {=C2=A0=C2=A0 =C2=A0}<br>};<br><br>class B {<br>public:<br>=C2=A0=C2=A0 =
=C2=A0B() : a(1) { }<br>=C2=A0=C2=A0 =C2=A0void f2() {<br>=C2=A0=C2=A0 =C2=
=A0=C2=A0=C2=A0 =C2=A0std::cout &lt;&lt; &quot;A:&quot; &lt;&lt; get_C_a().=
z &lt;&lt; std::endl;<br>=C2=A0=C2=A0 =C2=A0}<br>=C2=A0=C2=A0 =C2=A0virtual=
 A const&amp; get_C_a() { return a; }<br>=C2=A0=C2=A0 =C2=A0A a; // Use onl=
y from B<br>};<br><br>class D : public B {<br>public:<br>=C2=A0=C2=A0 =C2=
=A0D() : a(3) { }<br>=C2=A0=C2=A0 =C2=A0void f2(){<br>=C2=A0=C2=A0 =C2=A0=
=C2=A0=C2=A0 =C2=A0std::cout &lt;&lt; &quot;C+A:&quot; &lt;&lt; a.z &lt;&lt=
; std::endl;<br>=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0B::f2();<br>=C2=A0=C2=
=A0 =C2=A0}<br>=C2=A0=C2=A0 =C2=A0C a; // Use C+A only from D<br>=C2=A0=C2=
=A0 =C2=A0A const&amp; get_C_a() override { return a; }<br>};<br><br>int ma=
in() {<br>=C2=A0=C2=A0 =C2=A0B b; D d;<br>=C2=A0=C2=A0 =C2=A0b.f2(); d.f2()=
;<br>=C2=A0=C2=A0 =C2=A0return 0;<br>}<br><br>/* OUTPUT:<br>A:1<br>C+A:3<br=
>A:3<br>*/<br><br>------------------------------<wbr>---------<br><br>This =
would be the best option, but not the ideal one. Ideally, &quot;C a;&quot; =
of D replace &quot;A a;&quot; of B, in this way D only uses C+A from &quot;=
C a;&quot; and B only uses A from &quot;A a;&quot;<br><br>This is my propos=
al, a keyword like &#39;virtual&#39; (or can be any other) in the variable =
of the same name that is replaced by the variable definition of the base cl=
ass.<br><br>Por ejemplo:<br>Code:<br>------------------------------<wbr>---=
------<br>#include &lt;iostream&gt;<br><br>class A {<br>public:<br>=C2=A0=
=C2=A0 =C2=A0A(int z_) : z(z_) {=C2=A0=C2=A0 =C2=A0}<br>=C2=A0=C2=A0 =C2=A0=
int z;<br>};<br><br>class C: public A {<br>public:<br>=C2=A0=C2=A0 =C2=A0C(=
int z_) : A(z_) {=C2=A0=C2=A0 =C2=A0}<br>};<br><br>class B {<br>public:<br>=
=C2=A0=C2=A0 =C2=A0B() : a(1) { }<br>=C2=A0=C2=A0 =C2=A0void f2() {<br>=C2=
=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0std::cout &lt;&lt; &quot;A:&quot; &lt;&l=
t; a.z &lt;&lt; std::endl;<br>=C2=A0=C2=A0 =C2=A0}<br>=C2=A0=C2=A0 =C2=A0vi=
rtual A a; // Use A only from B<br>};<br><br>class D : public B {<br>public=
:<br>=C2=A0=C2=A0 =C2=A0D() : a(3) { }<br>=C2=A0=C2=A0 =C2=A0void f2(){<br>=
=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0std::cout &lt;&lt; &quot;C+A:&quot; &=
lt;&lt; a.z &lt;&lt; std::endl;<br>=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0B:=
:f2();<br>=C2=A0=C2=A0 =C2=A0}<br>=C2=A0=C2=A0 =C2=A0virtual C a; // Use C+=
A only from D<br>};<br><br>int main() {<br>=C2=A0=C2=A0 =C2=A0B b; D d;<br>=
=C2=A0=C2=A0 =C2=A0b.f2(); d.f2();<br>=C2=A0=C2=A0 =C2=A0return 0;<br>}<br>=
<br>/* OUTPUT:<br>A:1<br>C+A:3<br>A:3<br>*/<br><br>------------------------=
------<wbr>---------<br><br>well this might not be possible, since compiled=
 the code, the binary code uses the data from an expected position in the v=
ariables within the classes, so removing it from the list could alter the s=
ize and position of the variables. On the other hand it would be possible, =
since reserving memory from A or from C as C+A, generates a group of variab=
les reserved in memories for each class even if it is C+A and calls functio=
ns of A which omits C of C+A Just to have A in view, this could be an advan=
tage.<br>I suggest some other option to simulate a replacement of variable =
A by C.<br>If there is a better method that fulfills the same purpose witho=
ut breaking with the basic structure proposed here then much better.<br><br=
>=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D<wbr>=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D<wbr>=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D<br><br>Tenemos 2 clases que contienen distin=
tos conjuntos de datos, uno necesita usar las funciones y variables de otra=
 clase, por lo que se incluye como miembro apuntando a la otra clase:<br><b=
r>=C2=A0=C2=A0 member<br>A -------&gt; B<br><br>Code:<br>------------------=
------------<wbr>---------<br><br>class A {<br>public:<br>=C2=A0=C2=A0 =C2=
=A0A(int z_) : z(z_) {=C2=A0=C2=A0 =C2=A0}<br>=C2=A0=C2=A0 =C2=A0int z;<br>=
};<br><br>class B {<br>public:<br>=C2=A0=C2=A0 =C2=A0B() : a(1) { }<br>=C2=
=A0=C2=A0 =C2=A0void f2() {<br>=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0std::c=
out &lt;&lt; &quot;A:&quot; &lt;&lt; a.z &lt;&lt; std::endl;<br>=C2=A0=C2=
=A0 =C2=A0}<br>=C2=A0=C2=A0 =C2=A0A a;<br>};<br><br>-----------------------=
-------<wbr>---------<br><br>Luego se necesita crear una herencia para cada=
 clase, ya que necesita cubrir una nueva capa de interfaz. Llamemos C y D, =
donde C usa la clase base A y D usa la clase base B.<br><br>=C2=A0=C2=A0 me=
mber<br>A ---------&gt; B<br>|=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0 |<br>|inheritance | inheritance<br>|=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 |<br>v=C2=A0 member=C2=
=A0=C2=A0=C2=A0 v<br>C ---------&gt; D<br><br>Code:<br>--------------------=
----------<wbr>---------<br><br>class A {<br>public:<br>=C2=A0=C2=A0 =C2=A0=
A(int z_) : z(z_) {=C2=A0=C2=A0 =C2=A0}<br>=C2=A0=C2=A0 =C2=A0int z;<br>};<=
br>class C: public A {<br>public:<br>=C2=A0=C2=A0 =C2=A0C(int y_) : y(y_), =
A(y_) {=C2=A0=C2=A0 =C2=A0}<br>=C2=A0=C2=A0 =C2=A0long y;<br>};<br><br>clas=
s B {<br>public:<br>=C2=A0=C2=A0 =C2=A0B() : a(1) { }<br>=C2=A0=C2=A0 =C2=
=A0void f2() {<br>=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0std::cout &lt;&lt; =
&quot;A:&quot; &lt;&lt; a.z &lt;&lt; std::endl;<br>=C2=A0=C2=A0 =C2=A0}<br>=
=C2=A0=C2=A0 =C2=A0A a;<br>};<br>class D: public B {<br>public:<br>=C2=A0=
=C2=A0 =C2=A0B() : a(3) { }<br>=C2=A0=C2=A0 =C2=A0void f2() {<br>=C2=A0=C2=
=A0 =C2=A0=C2=A0=C2=A0 =C2=A0std::cout &lt;&lt; &quot;A:&quot; &lt;&lt; a.z=
 &lt;&lt; std::endl;<br>=C2=A0=C2=A0 =C2=A0}<br>=C2=A0=C2=A0 =C2=A0C a;<br>=
};<br><br>------------------------------<wbr>---------<br><br>=C2=A0 Aqui d=
onde aparecen los problemas, si creas B puedes acceder a los datos de A con=
 las funciones de B. Pero si creas D, accedes a los datos de C+A con las fu=
nciones de D y C, pero tan pronto llamas a las funciones heredadas de B, B =
solo puede acceder a los datos de A que estan totalmente en desuso, es deci=
r, crear una instancia en D genera en la memoria una variable &quot;a&quot;=
 con C+A, y tambien una variable &quot;a&quot; con A, siendo en la clase D =
un C+A,A , donde la ultima A no se usa, solo C+A , en A se termina usando c=
uando se llama a las funciones de B.<br>=C2=A0=C2=A0 =C2=A0Solo es posible =
crear una nueva funcion tipo virtual como unico caso para acceder solamente=
 a C+A, pero esto genera codigo basura y en la memoria se reserva A como ba=
sura:<br><br>Code:<br>------------------------------<wbr>---------<br>#incl=
ude &lt;iostream&gt;<br><br>class A {<br>public:<br>=C2=A0=C2=A0 =C2=A0A(in=
t z_) : z(z_) {=C2=A0=C2=A0 =C2=A0}<br>=C2=A0=C2=A0 =C2=A0int z;<br>};<br><=
br>class C: public A {<br>public:<br>=C2=A0=C2=A0 =C2=A0C(int z_) : A(z_) {=
=C2=A0=C2=A0 =C2=A0}<br>};<br><br>class B {<br>public:<br>=C2=A0=C2=A0 =C2=
=A0B() : a(1) { }<br>=C2=A0=C2=A0 =C2=A0void f2() {<br>=C2=A0=C2=A0 =C2=A0=
=C2=A0=C2=A0 =C2=A0std::cout &lt;&lt; &quot;A:&quot; &lt;&lt; get_C_a().z &=
lt;&lt; std::endl;<br>=C2=A0=C2=A0 =C2=A0}<br>=C2=A0=C2=A0 =C2=A0virtual A =
const&amp; get_C_a() { return a; }<br>=C2=A0=C2=A0 =C2=A0A a; // Use only f=
rom B<br>};<br><br>class D : public B {<br>public:<br>=C2=A0=C2=A0 =C2=A0D(=
) : a(3) { }<br>=C2=A0=C2=A0 =C2=A0void f2(){<br>=C2=A0=C2=A0 =C2=A0=C2=A0=
=C2=A0 =C2=A0std::cout &lt;&lt; &quot;C+A:&quot; &lt;&lt; a.z &lt;&lt; std:=
:endl;<br>=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0B::f2();<br>=C2=A0=C2=A0 =
=C2=A0}<br>=C2=A0=C2=A0 =C2=A0C a; // Use C+A only from D<br>=C2=A0=C2=A0 =
=C2=A0A const&amp; get_C_a() override { return a; }<br>};<br><br>int main()=
 {<br>=C2=A0=C2=A0 =C2=A0B b; D d;<br>=C2=A0=C2=A0 =C2=A0b.f2(); d.f2();<br=
>=C2=A0=C2=A0 =C2=A0return 0;<br>}<br><br>/* OUTPUT:<br>A:1<br>C+A:3<br>A:3=
<br>*/<br><br>------------------------------<wbr>---------<br><br>Esta seri=
a la mejor opcion, pero no la ideal. Lo ideal es que &quot;C a;&quot; de D =
remplace a &quot;A a;&quot; de B, de esta forma D solo usa C+A de &quot;C a=
;&quot; y B solo usa A de &quot;A a;&quot;<br><br>Esta es mi propuesta, una=
 palabra clave como &#39;virtual&#39; (o puede ser cualquier otra) en la va=
riable del mismo nombre que se remplace a la definicion de variable de la c=
lase base.<br><br>Por ejemplo:<br>Code:<br>------------------------------<w=
br>---------<br>#include &lt;iostream&gt;<br><br>class A {<br>public:<br>=
=C2=A0=C2=A0 =C2=A0A(int z_) : z(z_) {=C2=A0=C2=A0 =C2=A0}<br>=C2=A0=C2=A0 =
=C2=A0int z;<br>};<br><br>class C: public A {<br>public:<br>=C2=A0=C2=A0 =
=C2=A0C(int z_) : A(z_) {=C2=A0=C2=A0 =C2=A0}<br>};<br><br>class B {<br>pub=
lic:<br>=C2=A0=C2=A0 =C2=A0B() : a(1) { }<br>=C2=A0=C2=A0 =C2=A0void f2() {=
<br>=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0std::cout &lt;&lt; &quot;A:&quot;=
 &lt;&lt; a.z &lt;&lt; std::endl;<br>=C2=A0=C2=A0 =C2=A0}<br>=C2=A0=C2=A0 =
=C2=A0virtual A a; // Use A only from B<br>};<br><br>class D : public B {<b=
r>public:<br>=C2=A0=C2=A0 =C2=A0D() : a(3) { }<br>=C2=A0=C2=A0 =C2=A0void f=
2(){<br>=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0std::cout &lt;&lt; &quot;C+A:=
&quot; &lt;&lt; a.z &lt;&lt; std::endl;<br>=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =
=C2=A0B::f2();<br>=C2=A0=C2=A0 =C2=A0}<br>=C2=A0=C2=A0 =C2=A0virtual C a; /=
/ Use C+A only from D<br>};<br><br><br></div></blockquote><div><br></div><d=
iv>[snip]</div><div> This problem sounds similar to the &quot;dual inherita=
nce<br>hierarchy&quot; problem that this reference:<br><br>https://pdfs.sem=
anticscholar.org/f403/361d9ef3dac96463787b852b605a918bc4fe.pdf<br><br>addre=
sses.=C2=A0 For example, the A and B classes above<br>correspond to the B1 =
and B2 classes in Figure 3 of the above<br>reference, and the C and D class=
es above correspond to the<br>D1 and D2 classes in Figure 3 of the above re=
ference.<br><br>Is that how it seems to you?<br><br>-regards,<br>Larry<br><=
br></div></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/ebc202be-4def-427a-95ff-7239efb4b89f%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/ebc202be-4def-427a-95ff-7239efb4b89f=
%40isocpp.org</a>.<br />

------=_Part_11542_1573015084.1531908273240--

------=_Part_11541_1987043502.1531908273240--

.
