220 39404 <3a9e87f5-de59-4297-8096-f8f887b9f656@isocpp.org> article
Path: news.gmane.org!.POSTED!not-for-mail
From: rmbeer2@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, 25 Jul 2018 10:16:43 -0700 (PDT)
Lines: 718
Approved: news@gmane.org
Message-ID: <3a9e87f5-de59-4297-8096-f8f887b9f656@isocpp.org>
References: <adc40bab-d824-440b-99b9-dab0ad6bd482@isocpp.org>
 <ebc202be-4def-427a-95ff-7239efb4b89f@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_9518_1313330686.1532539003444"
X-Trace: blaine.gmane.org 1532538879 30550 195.159.176.226 (25 Jul 2018 17:14:39 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Wed, 25 Jul 2018 17:14:39 +0000 (UTC)
Cc: rmbeer2@gmail.com, cppljevans@gmail.com
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBDI6L6W3SYLBB7HA4LNAKGQE7IPLSQQ@isocpp.org Wed Jul 25 19:14:35 2018
Return-path: <std-proposals+bncBDI6L6W3SYLBB7HA4LNAKGQE7IPLSQQ@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-yb0-f199.google.com ([209.85.213.199])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBDI6L6W3SYLBB7HA4LNAKGQE7IPLSQQ@isocpp.org>)
	id 1fiNMw-0007qM-HT
	for gclcip-std-proposals@m.gmane.org; Wed, 25 Jul 2018 19:14:34 +0200
Original-Received: by mail-yb0-f199.google.com with SMTP id b12-v6sf4258349ybr.12
        for <gclcip-std-proposals@m.gmane.org>; Wed, 25 Jul 2018 10:16:45 -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=eF7Q6VtXHhyWUTeoEjIogD7u/cB2NIPYRDMx7NntMHE=;
        b=i/7jB9vrRsxHPFEvX+xNFaC9VHieg402z6U7dJ01D2oNtI4QaQFpkH7k895So8qzCU
         kGQXrBpThriYJGc9hPz+YK16uRt7hFzIOdH9w5Bs0dz293UYOc2PR1+kgO5f1pQpCQZR
         GJrwtZmfkXA8G1tqNSg8HLLwztfX6NyNxapIUCBobNq6FOEP2jT6zrGfyuupr6lHxqXa
         +fThHsVQOwjOfWXKGj7J8PPyyBTqYXzu3fH0Lb7CufK/YTYit53+nythidCpIQ54Edb5
         QAUhOiDW0wKdWBt8zKZ3pXs+ztScqBXyvlC8ieNqxRJQUsMiZ5d1qNJHykMTBedbpw9y
         hXag==
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=eF7Q6VtXHhyWUTeoEjIogD7u/cB2NIPYRDMx7NntMHE=;
        b=bULGTnSZ5RV3uDNkDnqEUvm3JKYseporuFlT//G/Q+4N4eXAxPH3G0ugcQScZqGi7z
         7GmndwGJpXnQHepPcn6DO+ELdkAlYOZg7EmeOvBFL/3PauOPTxOER0oSboQNMhiqczIS
         QNlBXD/B26iDkdyY47tQLlJrzp5+PhhOPpAN5ySz39BJtBoydt/Ci+TN3jvrUVIqG8Xr
         tYRm5F5Vdcv9fFjHK6CLeC9wm99YWNYAlC+pkUCH6J0bRLlQpFKm0zSE8bsXSktOhGqc
         LliNY/8+83uELoZcllYgMQltWRKKuxOj59SQO6Xx4pgN3wCzyIRmxJxwo+YN42X7y5RQ
         g86g==
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=eF7Q6VtXHhyWUTeoEjIogD7u/cB2NIPYRDMx7NntMHE=;
        b=hD8lhJ5Y1Bo+ArJONrChDO9UA2xzylb5sn/p+rrMW2WbJtWHcTcicM0V/dieE1GRXH
         J4YdrbSzAu3Ow/N4FcrabA+Nb9ZDEeG9D5WzGKA2ldoY9/2F+M9Ff3RDlGu4UvHfBqmT
         uxX5jJLI8zQzzj3gKZnTV8gQmuk5AwrHgpr6v7PnIU/szIiV3hr1RlfMfCIaIcFglrvj
         5wxC//zDzBN2cfLRlE5ITOr9MYVlIH3mhi0tK1Ygx6mGTNRTANKl9gAblRWx4PMMWw53
         rGJ/EahjfyBZdQGhGw85KHPnAu4Eofh/6KnswQYuJvHOusC3WrhMACqxWJYsLBlTHFRU
         /9Jw==
X-Gm-Message-State: AOUpUlFigH3y66RSU0qCu/drwqxOUY7tD9dFz1e9kmZy7cSWziLVudU4
	zSDNqvGywtDlioGevFLMaRme6A==
X-Google-Smtp-Source: AAOMgpdTMYU/lfxSTdcMEX5xnDjYrJ7D94zmXO+hoZA87qhH0RhdarDObKRTcvONOEv96p88P77JCQ==
X-Received: by 2002:a81:f95:: with SMTP id 143-v6mr7197974ywp.188.1532539004980;
        Wed, 25 Jul 2018 10:16:44 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 2002:a25:888b:: with SMTP id d11-v6ls3532874ybl.1.gmail; Wed, 25
 Jul 2018 10:16:44 -0700 (PDT)
X-Received: by 2002:a5b:60f:: with SMTP id d15-v6mr371765ybq.6.1532539003899;
        Wed, 25 Jul 2018 10:16:43 -0700 (PDT)
In-Reply-To: <ebc202be-4def-427a-95ff-7239efb4b89f@isocpp.org>
X-Original-Sender: rmbeer2@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:39404
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/39404>

------=_Part_9518_1313330686.1532539003444
Content-Type: multipart/alternative; 
	boundary="----=_Part_9519_957408359.1532539003445"

------=_Part_9519_957408359.1532539003445
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Yes, that's exactly what I was looking for!
I did not know that the keyword 'mutable' had to be used, although there is=
=20
still the problem of having to use the virtual function to directly extract=
=20
the class already converted from a parent class...
The class structure that I use is similar, but directly uses a "D2 itsD2;",=
=20
a direct statement within the class itself...

=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=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=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D

si, es justamente lo que estaba buscando!...
no sabia que habia que usar la palabra clave 'mutable', aunque sigue=20
estando el problema de tener que usar la funcion virtual para extraer=20
directamente la clase ya convertida desde una clase padre...
La estructura de clases que yo uso es similar, pero usa directamente un "D2=
=20
itsD2;", una declaraci=C3=B3n directa dentro de la propia clase...

El mi=C3=A9rcoles, 18 de julio de 2018, 7:04:33 (UTC-3), cpplj...@gmail.com=
=20
escribi=C3=B3:
>
>
>
> 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=
=20
>> functions and variables of another class, so it is included as a member=
=20
>> 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=
=20
>> cover a new interface layer. Let's call C and D, where C uses the base=
=20
>> 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=
=20
>> of A with the functions of B. But if you create D, you access the data o=
f=20
>> C+A with the functions of D and C, but as soon as you call the functions=
=20
>> inherited from B, B can only access the data of A that are totally in=20
>> disuse, that is, create an instance in D generates in memory a variable =
"a"=20
>> with C+A, and also a variable "a" with A , being in class D a C+A, A, wh=
ere=20
>> the last A is not used, only C+A, in A it ends up using when the functio=
ns=20
>> of B. are called.
>>   It is only possible to create a new virtual type function as the only=
=20
>> case to access only C+A, but this generates junk code and in memory it=
=20
>> 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=
=20
>> D replace "A a;" of B, in this way D only uses C+A from "C a;" and B onl=
y=20
>> uses A from "A a;"
>>
>> This is my proposal, a keyword like 'virtual' (or can be any other) in=
=20
>> the variable of the same name that is replaced by the variable definitio=
n=20
>> 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 cod=
e=20
>> uses the data from an expected position in the variables within the=20
>> classes, so removing it from the list could alter the size and position =
of=20
>> the variables. On the other hand it would be possible, since reserving=
=20
>> memory from A or from C as C+A, generates a group of variables reserved =
in=20
>> memories for each class even if it is C+A and calls functions of A which=
=20
>> 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=20
>> breaking with the basic structure proposed here then much better.
>>
>>
>> =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=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=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D
>>
>> Tenemos 2 clases que contienen distintos conjuntos de datos, uno necesit=
a=20
>> usar las funciones y variables de otra clase, por lo que se incluye como=
=20
>> 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=20
>> cubrir una nueva capa de interfaz. Llamemos C y D, donde C usa la clase=
=20
>> 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=20
>> datos de A con las funciones de B. Pero si creas D, accedes a los datos =
de=20
>> C+A con las funciones de D y C, pero tan pronto llamas a las funciones=
=20
>> heredadas de B, B solo puede acceder a los datos de A que estan totalmen=
te=20
>> en desuso, es decir, crear una instancia en D genera en la memoria una=
=20
>> variable "a" con C+A, y tambien una variable "a" con A, siendo en la cla=
se=20
>> D un C+A,A , donde la ultima A no se usa, solo C+A , en A se termina usa=
ndo=20
>> cuando se llama a las funciones de B.
>>     Solo es posible crear una nueva funcion tipo virtual como unico caso=
=20
>> para acceder solamente a C+A, pero esto genera codigo basura y en la=20
>> 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=20
>> remplace a "A a;" de B, de esta forma D solo usa C+A de "C a;" y B solo =
usa=20
>> A de "A a;"
>>
>> Esta es mi propuesta, una palabra clave como 'virtual' (o puede ser=20
>> cualquier otra) en la variable del mismo nombre que se remplace a la=20
>> 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/361d9ef3dac96463787b852b605a918bc4f=
e.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
>
>

--=20
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 e=
mail 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/3a9e87f5-de59-4297-8096-f8f887b9f656%40isocpp.or=
g.

------=_Part_9519_957408359.1532539003445
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Yes, that&#39;s exactly what I was looking for!<br>I did n=
ot know that the keyword &#39;mutable&#39; had to be used, although there i=
s still the problem of having to use the virtual function to directly extra=
ct the class already converted from a parent class...<br>The class structur=
e that I use is similar, but directly uses a &quot;D2 itsD2;&quot;, a direc=
t statement within the class itself...<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=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=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D<br><br>si, =
es justamente lo que estaba buscando!...<br>no sabia que habia que usar la =
palabra clave &#39;mutable&#39;, aunque sigue estando el problema de tener =
que usar la funcion virtual para extraer directamente la clase ya convertid=
a desde una clase padre...<br>La estructura de clases que yo uso es similar=
, pero usa directamente un &quot;D2 itsD2;&quot;, una declaraci=C3=B3n dire=
cta dentro de la propia clase...<br><br>El mi=C3=A9rcoles, 18 de julio de 2=
018, 7:04:33 (UTC-3), cpplj...@gmail.com escribi=C3=B3:<blockquote class=3D=
"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc s=
olid;padding-left: 1ex;"><div dir=3D"ltr"><br><br>On Monday, June 11, 2018 =
at 7:17:54 PM UTC-5, <a>rmb...@gmail.com</a> wrote:<blockquote class=3D"gma=
il_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;pa=
dding-left:1ex"><div dir=3D"ltr">We have 2 classes that contain different d=
ata 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>cl=
ass 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 interface layer. Let&#39;s call C and D, where C us=
es the base class A and D uses 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>|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=A0A(i=
nt 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>class B=
 {<br>public:<br>=C2=A0=C2=A0 =C2=A0B() : a(1) { }<br>=C2=A0=C2=A0 =C2=A0vo=
id 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>};<b=
r><br>------------------------------<wbr>---------<br><br>Here where the pr=
oblems appear, if you create B you can access the data of A with the functi=
ons of B. But if you create D, you access the data of C+A with the function=
s 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 i=
nstance in D generates in memory a variable &quot;a&quot; with C+A, and als=
o a variable &quot;a&quot; with A , being in class D a C+A, A, where the la=
st A is not used, only C+A, in A it ends up using when the functions of B. =
are called.<br>=C2=A0 It is only possible to create a new virtual type func=
tion as the only case to access 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>publ=
ic:<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>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 from B<br>};<br><br>class D : public B {<br>p=
ublic:<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:&qu=
ot; &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 o=
nly 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>/* OU=
TPUT:<br>A:1<br>C+A:3<br>A:3<br>*/<br><br>------------------------------<wb=
r>---------<br><br>This would be the best option, but not the ideal one. Id=
eally, &quot;C a;&quot; of D replace &quot;A a;&quot; of B, in this way D o=
nly uses C+A from &quot;C a;&quot; and B only uses A from &quot;A a;&quot;<=
br><br>This is my proposal, a keyword like &#39;virtual&#39; (or can be any=
 other) in the variable of the same name that is replaced by the variable d=
efinition of the base class.<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=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>cl=
ass 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=A0virtual 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;&l=
t; &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=A0v=
irtual 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 ex=
pected position in the variables within the classes, so removing it from th=
e list could alter the size and position of the variables. On the other han=
d it would be possible, since reserving memory from A or from C as C+A, gen=
erates 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.<br>I suggest some other option to simulate a =
replacement of variable A by C.<br>If there is a better method that fulfill=
s the same purpose without 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 cla=
ses que contienen distintos conjuntos de datos, uno necesita usar las funci=
ones y variables de otra clase, por lo que se incluye como miembro apuntand=
o a la otra clase:<br><br>=C2=A0=C2=A0 member<br>A -------&gt; B<br><br>Cod=
e:<br>------------------------------<wbr>---------<br><br>class A {<br>publ=
ic:<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>Luego se necesita crear=
 una herencia para cada clase, ya que necesita cubrir una nueva capa de int=
erfaz. Llamemos C y D, donde C usa la clase base A y D usa la clase base 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>|inheritance | inheritan=
ce<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:<b=
r>=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>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=A0=
long 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>};<br>class D: public B=
 {<br>public:<br>=C2=A0=C2=A0 =C2=A0B() : a(3) { }<br>=C2=A0=C2=A0 =C2=A0vo=
id 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 donde aparecen los problemas, si creas B puedes acce=
der 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 func=
iones heredadas de B, B solo puede acceder a los datos de A que estan total=
mente en desuso, es decir, crear una instancia en D genera en la memoria un=
a 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 cuando se llama a las funciones de B.<br>=C2=A0=C2=
=A0 =C2=A0Solo es posible crear una nueva funcion tipo virtual como unico c=
aso para acceder solamente a C+A, pero esto genera codigo basura y en la me=
moria se reserva A como basura:<br><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=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:&q=
uot; &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 from B<br>};<br><br>class D : public B {<br>p=
ublic:<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:&qu=
ot; &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 o=
nly 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>/* OU=
TPUT:<br>A:1<br>C+A:3<br>A:3<br>*/<br><br>------------------------------<wb=
r>---------<br><br>Esta seria la mejor opcion, pero no la ideal. Lo ideal e=
s 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 variable del mismo nombre que se remplace a la de=
finicion de variable de la clase base.<br><br>Por ejemplo:<br>Code:<br>----=
--------------------------<wbr>---------<br>#include &lt;iostream&gt;<br><b=
r>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 {<b=
r>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::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=A0virtual A a; // Use A only from B<br>};<b=
r><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=A0s=
td::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><div>[snip]</div><div> This problem sounds simi=
lar to the &quot;dual inheritance<br>hierarchy&quot; problem that this refe=
rence:<br><br><a href=3D"https://pdfs.semanticscholar.org/f403/361d9ef3dac9=
6463787b852b605a918bc4fe.pdf" target=3D"_blank" rel=3D"nofollow" onmousedow=
n=3D"this.href=3D&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fpdfs.se=
manticscholar.org%2Ff403%2F361d9ef3dac96463787b852b605a918bc4fe.pdf\x26sa\x=
3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEQHoEJF7O51Coju_EhQAXdD0kSNw&#39;;return t=
rue;" onclick=3D"this.href=3D&#39;https://www.google.com/url?q\x3dhttps%3A%=
2F%2Fpdfs.semanticscholar.org%2Ff403%2F361d9ef3dac96463787b852b605a918bc4fe=
..pdf\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEQHoEJF7O51Coju_EhQAXdD0kSNw&#=
39;;return true;">https://pdfs.semanticscholar.<wbr>org/f403/<wbr>361d9ef3d=
ac96463787b852b605a91<wbr>8bc4fe.pdf</a><br><br>addresses.=C2=A0 For exampl=
e, the A and B classes above<br>correspond to the B1 and B2 classes in Figu=
re 3 of the above<br>reference, and the C and D classes above correspond to=
 the<br>D1 and D2 classes in Figure 3 of the above reference.<br><br>Is tha=
t how it seems to you?<br><br>-regards,<br>Larry<br><br></div></div></block=
quote></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/3a9e87f5-de59-4297-8096-f8f887b9f656%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/3a9e87f5-de59-4297-8096-f8f887b9f656=
%40isocpp.org</a>.<br />

------=_Part_9519_957408359.1532539003445--

------=_Part_9518_1313330686.1532539003444--

.
