220 39706 <16c8ccb9-8e42-46cc-9129-52e1129617be@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: Sat, 11 Aug 2018 08:50:01 -0700 (PDT)
Lines: 803
Approved: news@gmane.org
Message-ID: <16c8ccb9-8e42-46cc-9129-52e1129617be@isocpp.org>
References: <adc40bab-d824-440b-99b9-dab0ad6bd482@isocpp.org>
 <ebc202be-4def-427a-95ff-7239efb4b89f@isocpp.org>
 <3a9e87f5-de59-4297-8096-f8f887b9f656@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_1089_674701743.1534002601469"
X-Trace: blaine.gmane.org 1534002478 16778 195.159.176.226 (11 Aug 2018 15:47:58 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Sat, 11 Aug 2018 15:47:58 +0000 (UTC)
Cc: rmbeer2@gmail.com, cppljevans@gmail.com
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBDI6L6W3SYLBBKULXTNQKGQEVCVVOOY@isocpp.org Sat Aug 11 17:47:53 2018
Return-path: <std-proposals+bncBDI6L6W3SYLBBKULXTNQKGQEVCVVOOY@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-yw1-f71.google.com ([209.85.161.71])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBDI6L6W3SYLBBKULXTNQKGQEVCVVOOY@isocpp.org>)
	id 1foW7N-0004GK-HH
	for gclcip-std-proposals@m.gmane.org; Sat, 11 Aug 2018 17:47:53 +0200
Original-Received: by mail-yw1-f71.google.com with SMTP id t10-v6sf16795680ywc.7
        for <gclcip-std-proposals@m.gmane.org>; Sat, 11 Aug 2018 08:50:04 -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=cwNt6/bLbryb/3mBFryV8pbt8X5S2Vp/sitKwbwfPv8=;
        b=CFUTkJPFWg8nzKAibDUnpDgfIwukyIUs/WoVatJPecj1vAFMsfB8PNxjZKdJlYsemM
         oO1+2axvDB6SdutgHr0VQbFbe9eZ5OZXW/ntmw6YSWYZee33QVIC/BBegb6BF6VpV/Uc
         gZWL/gOD4ls4O/y6SvGyETIu6WVqT+zNNINCxB0Sd6xPNDTnM3dpBQp97QSTNAN9Q9xP
         8YVuckQgtIEr/GRA9qclD/iORrCBvt1PmeQu38Fa0Y2zcybEnrgjVJSznEdW72aPu1TW
         yKDK8LVnzVlwjKHdbxAsd/TFQ5zfXw3a53yqy7BL8hWFl1MeFyWgduu4nTWSi+QdxOne
         /yew==
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=cwNt6/bLbryb/3mBFryV8pbt8X5S2Vp/sitKwbwfPv8=;
        b=TelIzPku3M1eTNMvI/eHVFxYBah60fGVENu3tJc2pHJ3ULsDEqZCm5Guu5UcrzloIk
         LDmeCCU5y6lL2hUTxpkvNEfwa8ex0iNYkw0n4w5InfgsPRx0dQOzngaxUAsWLdJyY1uf
         oW0n0dzriCSReYtKxLqtXVX2ZA49bx97yHFUl8twx6J3pEGR/gY1m0bV9ydgOjFbB2vc
         13/7HbuZsrXLMBV2zbn9Wtb4KkaTCldnjk2p6mq3yWG2iY+cabWkFNWUPRLX3Crfte6w
         9djjgynP1a7DddTKo6E88DcOpVjHz7Y+VdlNpwmr81dTFmk0/ZFUJsdGcJbZRpUkuDRb
         o+hQ==
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=cwNt6/bLbryb/3mBFryV8pbt8X5S2Vp/sitKwbwfPv8=;
        b=WidWljpCKHi2IkgRd1rK3PJZjJJ+KBbUgPW4zU7nfFApW0XiGvFENRXsvmJnKInYF9
         tNjlDCiClx5pZ2sgqJLcpguRjlEZ4e8n7f/X642TTewSGGqsT3aUCWo25580w+krf14V
         BS8VQnqDF2xWfzqM9gimUab2PVXljv9qvvCfs0ryKIs8KzbuAFrWvX/bXv/2ztUgYSev
         rtlvwL23AcwxAtsOEai/XWoQftzvXztjXepZlXU6hT7+YU0u8R7mzAAQIAfyh3GRmtHD
         l3D5HaxXyS35X7hEnly22+uQG0F3tjhdzx2PAF9x9qK3VypRmp/bJPAB/MysKWheObZ+
         1SHw==
X-Gm-Message-State: AOUpUlH3TAJLXeEVAxL0Nga6itmX/Z5Kaxy0NGMBHv3zYyiDSDT0IECY
	npEn6Ww5sfTRv+ewPbKzKJMbRw==
X-Google-Smtp-Source: AA+uWPws5+A+Pi+Jvycr76AEeRxf1/njzov0EO/ZWtv8/Wvd5nQz7F/9u41l936eOGHnNhoNKXQtHQ==
X-Received: by 2002:a0d:fd46:: with SMTP id n67-v6mr3479151ywf.60.1534002603665;
        Sat, 11 Aug 2018 08:50:03 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 2002:a25:e68a:: with SMTP id d132-v6ls2472231ybh.9.gmail; Sat, 11
 Aug 2018 08:50:02 -0700 (PDT)
X-Received: by 2002:a25:8448:: with SMTP id r8-v6mr124842ybm.2.1534002602109;
        Sat, 11 Aug 2018 08:50:02 -0700 (PDT)
In-Reply-To: <3a9e87f5-de59-4297-8096-f8f887b9f656@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:39706
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/39706>

------=_Part_1089_674701743.1534002601469
Content-Type: multipart/alternative; 
	boundary="----=_Part_1090_899285510.1534002601470"

------=_Part_1090_899285510.1534002601470
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

La soluci=C3=B3n que me ofrecieron en este lugar fue esta:

Codigo:
=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
class B1
{
public:
  virtual B2& GetB2() const =3D 0;
};
class B2 {};
class D2 : public B2 {};
class D1 : public B1
{
public:
  D1(D2& d2) : itsD2(d2) {};
  virtual D2& GetB2() const {return itsD2;}
private:
  mutable D2& itsD2;
};
=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

Pero tiene el problema de que luego necesitas reemplazar todo "itsD2." por=
=20
"GetB2().", esto es una mala practica y solo crea codigo basura. Al final=
=20
es mejor utilizar el lenguaje C en el medio, algo asi como remplazar estas=
=20
lineas por las otras siguientes:

Original:
GetB2().var;
GetB2().var;
GetB2().var;

Mejorado:
D2&d2=3D*((D2)itsD2);
d2.var;
d2.var;
d2.var;

Es decir, hacer una referencia de un "void*itsD2;" desde B1 en lugar de un=
=20
"mutable D2&itsD2;" en D1....

la finalidad de esta propuesta es utilizar "d2.var" en lugar de=20
"GetB2().var", insisto en que mi propuesta es la mejor, si no logran=20
mejorar C++ para aceptar el uso de este tipo de variables entonces voy a=20
insistir en el viejo habito de C...


El mi=C3=A9rcoles, 25 de julio de 2018, 14:16:43 (UTC-3), rmb...@gmail.com=
=20
escribi=C3=B3:
>
> Yes, that's exactly what I was looking for!
> I did not know that the keyword 'mutable' had to be used, although there=
=20
> is still the problem of having to use the virtual function to directly=20
> extract the class already converted from a parent class...
> The class structure that I use is similar, but directly uses a "D2=20
> itsD2;", 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=
=20
> "D2 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.c=
om=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 th=
e=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 t=
o=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 =
of=20
>>> C+A with the functions of D and C, but as soon as you call the function=
s=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, w=
here=20
>>> the last A is not used, only C+A, in A it ends up using when the functi=
ons=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;" o=
f=20
>>> D replace "A a;" of B, in this way D only uses C+A from "C a;" and B on=
ly=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 definiti=
on=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=20
>>> code uses the data from an expected position in the variables within th=
e=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 whic=
h=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=20
>>> necesita usar las funciones y variables de otra clase, por lo que se=20
>>> 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=
=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 totalme=
nte=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 cl=
ase=20
>>> D un C+A,A , donde la ultima A no se usa, solo C+A , en A se termina us=
ando=20
>>> cuando se llama a las funciones de B.
>>>     Solo es posible crear una nueva funcion tipo virtual como unico cas=
o=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=
=20
>>> D remplace a "A a;" de B, de esta forma D solo usa C+A de "C a;" y B so=
lo=20
>>> usa 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/361d9ef3dac96463787b852b605a918bc4=
fe.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/16c8ccb9-8e42-46cc-9129-52e1129617be%40isocpp.or=
g.

------=_Part_1090_899285510.1534002601470
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">La soluci=C3=B3n que me ofrecieron en este lugar fue esta:=
<br><br>Codigo:<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>class B1<br>{<br>public:<br>=C2=A0 =
virtual B2&amp; GetB2() const =3D 0;<br>};<br>class B2 {};<br>class D2 : pu=
blic B2 {};<br>class D1 : public B1<br>{<br>public:<br>=C2=A0 D1(D2&amp; d2=
) : itsD2(d2) {};<br>=C2=A0 virtual D2&amp; GetB2() const {return itsD2;}<b=
r>private:<br>=C2=A0 mutable D2&amp; itsD2;<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><b=
r>Pero tiene el problema de que luego necesitas reemplazar todo &quot;itsD2=
..&quot; por &quot;GetB2().&quot;, esto es una mala practica y solo crea cod=
igo basura. Al final es mejor utilizar el lenguaje C en el medio, algo asi =
como remplazar estas lineas por las otras siguientes:<br><br>Original:<br>G=
etB2().var;<br>GetB2().var;<br>GetB2().var;<br><br>Mejorado:<br>D2&amp;d2=
=3D*((D2)itsD2);<br>d2.var;<br>d2.var;<br>d2.var;<br><br>Es decir, hacer un=
a referencia de un &quot;void*itsD2;&quot; desde B1 en lugar de un &quot;mu=
table D2&amp;itsD2;&quot; en D1....<br><br>la finalidad de esta propuesta e=
s utilizar &quot;d2.var&quot; en lugar de &quot;GetB2().var&quot;, insisto =
en que mi propuesta es la mejor, si no logran mejorar C++ para aceptar el u=
so de este tipo de variables entonces voy a insistir en el viejo habito de =
C...<br><br><br>El mi=C3=A9rcoles, 25 de julio de 2018, 14:16:43 (UTC-3), r=
mb...@gmail.com escribi=C3=B3:<blockquote class=3D"gmail_quote" style=3D"ma=
rgin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">=
<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<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>si, es justamente lo que estaba buscando!...<br>no sabia que habia q=
ue usar la palabra clave &#39;mutable&#39;, aunque sigue estando el problem=
a de tener que usar la funcion virtual para extraer directamente la clase y=
a convertida 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 directa dentro de la propia clase...<br><br>El mi=C3=A9rcoles, 18 d=
e julio de 2018, 7:04:33 (UTC-3), <a>cpplj...@gmail.com</a> escribi=C3=B3:<=
blockquote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border=
-left:1px #ccc solid;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:<blockquot=
e class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px=
 #ccc solid;padding-left:1ex"><div dir=3D"ltr">We have 2 classes that conta=
in different data sets, one needs to use the functions and variables of ano=
ther 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::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>Then you need to create an inheritance for eac=
h class, since you need to cover a new interface layer. Let&#39;s call C an=
d D, where C uses 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(int z_) : z(z_) {=C2=A0=C2=A0 =C2=A0}<br>=C2=A0=C2=A0 =C2=A0=
int 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=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>class D: public B {<br>publ=
ic:<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 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 inher=
ited from B, B can only access the data of A that are totally in disuse, th=
at 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 th=
e functions of B. are called.<br>=C2=A0 It is only possible to create a new=
 virtual type function as the only case to access only C+A, but this genera=
tes 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=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>p=
ublic:<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() { retur=
n a; }<br>=C2=A0=C2=A0 =C2=A0A a; // Use 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=A0C=
 a; // Use C+A only from D<br>=C2=A0=C2=A0 =C2=A0A const&amp; get_C_a() ove=
rride { 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>This would be the best option, but not th=
e 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 &q=
uot;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 definition 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>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=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;&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 mai=
n() {<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 t=
his might not be possible, since compiled the code, the binary code uses th=
e data from an expected position in the variables within the classes, so re=
moving 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 f=
rom 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.<br>I suggest some other opti=
on to simulate a replacement of variable A by C.<br>If there is a better me=
thod that fulfills the same purpose without breaking with the basic structu=
re 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 distintos conjuntos de datos, uno necesita =
usar las funciones y variables de otra clase, por lo que se incluye como mi=
embro apuntando a la otra clase:<br><br>=C2=A0=C2=A0 member<br>A -------&gt=
; B<br><br>Code:<br>------------------------------<wbr>---------<br><br>cla=
ss 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>Luego se n=
ecesita crear una herencia para cada clase, ya que necesita cubrir una nuev=
a 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 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<b=
r><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>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=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 &l=
t;&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 acceder a los datos de A con las funciones de B. Pero si creas D, ac=
cedes 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 &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 com=
o unico caso para acceder solamente a C+A, pero esto genera codigo basura y=
 en la memoria 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>cla=
ss 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>public:<br>=C2=A0=C2=A0 =C2=A0D() : a(3) { }<br>=C2=A0=C2=A0 =C2=A0voi=
d 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; // Us=
e C+A only from D<br>=C2=A0=C2=A0 =C2=A0A const&amp; get_C_a() override { r=
eturn 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 seria la mejor opcion, pero no la ideal. Lo i=
deal 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 variable del mismo nombre que se remplace a=
 la definicion de variable de la clase base.<br><br>Por ejemplo:<br>Code:<b=
r>------------------------------<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:&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;&lt; &quot;C+A:&quot; &lt;&lt; a.z &lt;&lt; std::en=
dl;<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 similar to the &quot;dual inheritance<br>hierarchy&quot; problem tha=
t this reference:<br><br><a href=3D"https://pdfs.semanticscholar.org/f403/3=
61d9ef3dac96463787b852b605a918bc4fe.pdf" rel=3D"nofollow" target=3D"_blank"=
 onmousedown=3D"this.href=3D&#39;https://www.google.com/url?q\x3dhttps%3A%2=
F%2Fpdfs.semanticscholar.org%2Ff403%2F361d9ef3dac96463787b852b605a918bc4fe.=
pdf\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEQHoEJF7O51Coju_EhQAXdD0kSNw&#3=
9;;return true;" onclick=3D"this.href=3D&#39;https://www.google.com/url?q\x=
3dhttps%3A%2F%2Fpdfs.semanticscholar.org%2Ff403%2F361d9ef3dac96463787b852b6=
05a918bc4fe.pdf\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEQHoEJF7O51Coju_EhQ=
AXdD0kSNw&#39;;return true;">https://pdfs.semanticscholar.<wbr>org/f403/<wb=
r>361d9ef3dac96463787b852b605a91<wbr>8bc4fe.pdf</a><br><br>addresses.=C2=A0=
 For example, the A and B classes above<br>correspond to the B1 and B2 clas=
ses in Figure 3 of the above<br>reference, and the C and D classes above co=
rrespond to the<br>D1 and D2 classes in Figure 3 of the above reference.<br=
><br>Is that how it seems to you?<br><br>-regards,<br>Larry<br><br></div></=
div></blockquote></div></blockquote></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/16c8ccb9-8e42-46cc-9129-52e1129617be%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/16c8ccb9-8e42-46cc-9129-52e1129617be=
%40isocpp.org</a>.<br />

------=_Part_1090_899285510.1534002601470--

------=_Part_1089_674701743.1534002601469--

.
