220 39715 <ef755674-802e-4354-a98d-a782ee90cce2@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 12:17:12 -0700 (PDT)
Lines: 842
Approved: news@gmane.org
Message-ID: <ef755674-802e-4354-a98d-a782ee90cce2@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_1145_861094225.1534015032839"
X-Trace: blaine.gmane.org 1534014909 29122 195.159.176.226 (11 Aug 2018 19:15:09 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Sat, 11 Aug 2018 19:15:09 +0000 (UTC)
Cc: rmbeer2@gmail.com
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBDI6L6W3SYLBBOPMXTNQKGQE6TS3EEA@isocpp.org Sat Aug 11 21:15:05 2018
Return-path: <std-proposals+bncBDI6L6W3SYLBBOPMXTNQKGQE6TS3EEA@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+bncBDI6L6W3SYLBBOPMXTNQKGQE6TS3EEA@isocpp.org>)
	id 1foZLs-0007UD-N5
	for gclcip-std-proposals@m.gmane.org; Sat, 11 Aug 2018 21:15:05 +0200
Original-Received: by mail-yw1-f71.google.com with SMTP id c67-v6sf17460898ywc.21
        for <gclcip-std-proposals@m.gmane.org>; Sat, 11 Aug 2018 12:17:15 -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=JG7FuazQVDq5iMKyrW7WO0+9T3AjDrDEbq+0iptMvu8=;
        b=kMHNGiRrHWY4pKUI2tFe7maZRh52yTn6/nvNeaoG/umflizufGAPur8h+v5oMuneby
         hHnYgmgIh5ZuCst2W/8KbfpOjNc8pWTNpIhq+aXH3LQg4mOGoQt83XmJPVtJvHOMBEc7
         bJDVi2R9xDCPjfwoiBu8qazCd7JZVMORV0VMT53jew7dycEJQnYvSFFqQUdZD0zSBgHs
         3CQeJeNlVh9YAeOvv1d7C0yPtf7sE3ITGUiJ0fexTOkZgwMkqh7eU5D7KiD/+6kCLVYY
         4OmzraUEFQLVkw66NXojFEb0YniJ0CxHboQ5E7kHnvqCl4w3ARb+sYKoUQYhhTKzgGiX
         jM8A==
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=JG7FuazQVDq5iMKyrW7WO0+9T3AjDrDEbq+0iptMvu8=;
        b=prDVGdBqeU0pCfyyOYg8JjOHSdyUH34azGHeIepM/3hdZ4s2oQhOYwUdpyVgNQbsdG
         GijbRPcfL/1/YtkdLNH32Z2Q5ZU4X7BRNlyCavuUgiLLuqFGeVvA6uzDEb/KJIfZM8xE
         zUy7YXjvWB+MZz+MI1goatRRjjrRjbTOUGodpCqd6zWDvIlEZmnrM/xGHf57BmUsOe24
         bmmDoAhwzOqAjFYgHC0nGXweG3iqlwgQ/SbqagpXphdx/f7r+ZmTKOa+t0kNEzPI8vsg
         PflTx38Z3gTsZftOQO/2QhAeAmf7zyrxDfZH5NAOpWlJymFwUuJjxr8jdHup11ODyKrf
         +Jeg==
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=JG7FuazQVDq5iMKyrW7WO0+9T3AjDrDEbq+0iptMvu8=;
        b=kGLi+IkxdUSYPoWiETexY5cdANfcM0N8SOYnC2XLzOex17cJPEl+5Y9vD3HAk8Q/YD
         tgA2UUbir70B/6AhgT/On6rYmPP/ps08tZSwmcnca9v2TS3mbOSMdOknPi41kT73Pjwj
         H67qBTd3ZUOjtALIJPxoTu0soNwFheu+2k2KaNqi+f8Fb+lonqFGRSO9NJxS3DXM1i1R
         y9DAVeq+Dm9giTdpsSqxJJexq/1n6PPjqPGg+6uwnUXzlZeGCpzSnB2TJ/X9J4MlgiR6
         owqS+lXYDnSPU/HwE5j2+nAG92Yx6NtWBmAkiIRlqssl/qIxhfTuPO2UxYfgaTXX0Z0a
         nXcQ==
X-Gm-Message-State: AOUpUlH9q2L09BgXVc1s105QfjNID/rU5ocoPJzAto1eIInU8XhZm7KW
	Tf80ry6vqo1KnctR6he61/3Tnw==
X-Google-Smtp-Source: AA+uWPwsIJtn+UKhsImyVe3r7uMMan2PW1rWuBV7wt+V8W5E92pZnlDS5n2UPvURz39ZTyXFxx5Bhw==
X-Received: by 2002:a81:e60a:: with SMTP id u10-v6mr3650884ywl.70.1534015034942;
        Sat, 11 Aug 2018 12:17:14 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 2002:a81:8386:: with SMTP id t128-v6ls1979018ywf.17.gmail; Sat,
 11 Aug 2018 12:17:13 -0700 (PDT)
X-Received: by 2002:a0d:de01:: with SMTP id h1-v6mr246597ywe.3.1534015033454;
        Sat, 11 Aug 2018 12:17:13 -0700 (PDT)
In-Reply-To: <adc40bab-d824-440b-99b9-dab0ad6bd482@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:39715
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/39715>

------=_Part_1145_861094225.1534015032839
Content-Type: multipart/alternative; 
	boundary="----=_Part_1146_100014087.1534015032840"

------=_Part_1146_100014087.1534015032840
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Es por eso que estoy publicando en este grupo, C++ no permite este tipo de=
=20
trabajo con 4 clases y con las siguientes respuestas de salidas.
Este es el codigo original con la que cuento, es la definitiva, combina C++=
=20
con C para compensar la carencia de C++. Si C++ no consigue resolver este=
=20
problema agregando alguna nueva caracteristica no me queda otra que=20
utilizar C con C++ y utilizando lineas de C para trabajar con memoria:

=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D

#include <stdio.h>

class A {
public:
  A(int z_) : z(z_) {    }
  virtual void f1(){printf("-> A (z): %d\n",z);}
  int z;
};
class C: public A {
public:
  C(int y_) : y(y_), A(y_) {    }
  virtual void f1(){printf("-> C (z): %d\n",z);A::f1();}
  long y;
};

class B {
public:
  B() { }
  virtual int init(){
    ptra=3Dnew A(1);
    if(!ptra)return -1;return 0;
  }
  virtual void f2() {
    A&a=3D*((A*)ptra);
    printf("B (a.z): %d\n",a.z);
    a.f1();
  }
  void*ptra;
};
class D: public B {
public:
  D() { }
  virtual int init(){
    ptra=3Dnew C(3);
    if(!ptra)return -1;return 0;
  }
  virtual void f2() {
    C&a=3D*((C*)ptra);
    printf("D (a.z): %d\n",a.z);
    a.f1();
    B::f2();
  }
};

int main(){
  D d;B b;

  if(d.init())return -1;
  if(b.init())return -1;
 =20
  b.f2();
  printf("=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D\n");
  d.f2();
  return 0;
}

/* RESPUESTA:
B (a.z): 1
-> A (z): 1
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
D (a.z): 3
-> C (z): 3
-> A (z): 3
B (a.z): 3
-> C (z): 3
-> A (z): 3
*/

=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D

Hasta ahora no he obtenido ningun resultado sastisfactorio.

El lunes, 11 de junio de 2018, 21:17:54 (UTC-3), rmb...@gmail.com escribi=
=C3=B3:
>
> 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 o=
f=20
> A with the functions of B. But if you create D, you access the data of C+=
A=20
> 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, whe=
re=20
> the last A is not used, only C+A, in A it ends up using when the function=
s=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 =
D=20
> replace "A a;" of B, in this way D only uses C+A from "C a;" and B only=
=20
> uses A from "A a;"
>
> This is my proposal, a keyword like 'virtual' (or can be any other) in th=
e=20
> variable of the same name that is replaced by the variable definition of=
=20
> 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=
=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 o=
f=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 i=
n=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 necesita=
=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 dato=
s=20
> de A con las funciones de B. Pero si creas D, accedes a los datos de C+A=
=20
> 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 totalment=
e=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 clas=
e=20
> D un C+A,A , donde la ultima A no se usa, solo C+A , en A se termina usan=
do=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 u=
sa=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
> };
>
> int main() {
>     B b; D d;
>     b.f2(); d.f2();
>     return 0;
> }
>
> /* OUTPUT:
> A:1
> C+A:3
> A:3
> */
>
> ---------------------------------------
>
> bien esto podria no ser posible, ya que compilado el codigo, el codigo=20
> binario utiliza los datos desde una posicion esperada en las variables=20
> dentro de las clases, por lo que eliminarlo de la lista podria alterar el=
=20
> tama=C3=B1o y la posicion de las variables. Por otro lado seria posible, =
ya que=20
> reservar memoria desde A o desde C como C+A, se genera un grupo de=20
> variables reservadas en memorias para cada clase incluso si es C+A y llam=
ar=20
> a funciones de A lo cual omite C de C+A solo para tener a la vista A,=20
> podria ser esto una ventaja.
> Sugiero alguna otra opcion para simular un remplazo de la variable A por =
C.
> Si existe algun metodo mejor que cumpla con el mismo proposito sin romper=
=20
> con la estructura basica propuesta aqui entonces mucho mejor.
>
>

--=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/ef755674-802e-4354-a98d-a782ee90cce2%40isocpp.or=
g.

------=_Part_1146_100014087.1534015032840
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>Es por eso que estoy publicando en este grupo, C++ no=
 permite este tipo de trabajo con 4 clases y con las siguientes respuestas =
de salidas.</div><div>Este es el codigo original con la que cuento, es la d=
efinitiva, combina C++ con C para compensar la carencia de C++. Si C++ no c=
onsigue resolver este problema agregando alguna nueva caracteristica no me =
queda otra que utilizar C con C++ y utilizando lineas de C para trabajar co=
n memoria:</div><div><br></div><div>=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D</div><div><pre>#include &lt;stdio.h&gt;

class A {
public:
  A(int z_) : z(z_) {    }
  virtual void f1(){printf(&quot;-&gt; A (z): %d\n&quot;,z);}
  int z;
};
class C: public A {
public:
  C(int y_) : y(y_), A(y_) {    }
  virtual void f1(){printf(&quot;-&gt; C (z): %d\n&quot;,z);A::f1();}
  long y;
};

class B {
public:
  B() { }
  virtual int init(){
    ptra=3Dnew A(1);
    if(!ptra)return -1;return 0;
  }
  virtual void f2() {
    A&amp;a=3D*((A*)ptra);
    printf(&quot;B (a.z): %d\n&quot;,a.z);
    a.f1();
  }
  void*ptra;
};
class D: public B {
public:
  D() { }
  virtual int init(){
    ptra=3Dnew C(3);
    if(!ptra)return -1;return 0;
  }
  virtual void f2() {
    C&amp;a=3D*((C*)ptra);
    printf(&quot;D (a.z): %d\n&quot;,a.z);
    a.f1();
    B::f2();
  }
};

int main(){
  D d;B b;

  if(d.init())return -1;
  if(b.init())return -1;
 =20
  b.f2();
  printf(&quot;=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D\n&quot;);
  d.f2();
  return 0;
}

/* RESPUESTA:
B (a.z): 1
-&gt; A (z): 1
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
D (a.z): 3
-&gt; C (z): 3
-&gt; A (z): 3
B (a.z): 3
-&gt; C (z): 3
-&gt; A (z): 3
*/
</pre></div><div>=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=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></div=
><div><br></div><div>Hasta ahora no he obtenido ningun resultado sastisfact=
orio.<br></div><br>El lunes, 11 de junio de 2018, 21:17:54 (UTC-3), rmb...@=
gmail.com 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 d=
ir=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 m=
ember pointing to the other class:<br><br>=C2=A0=C2=A0 member<br>A -------&=
gt; B<br><br>Code:<br>------------------------------<wbr>---------<br><br>c=
lass 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;&l=
t; 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 yo=
u need to create an inheritance for each class, since you need to cover a n=
ew interface layer. Let&#39;s call C and D, where C uses the base class A a=
nd 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 |<b=
r>|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=A0int z;<br>};<br>class C: public A {<br>pu=
blic:<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) { }<b=
r>=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;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>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>bien esto podria no ser posible, ya que=
 compilado el codigo, el codigo binario utiliza los datos desde una posicio=
n esperada en las variables dentro de las clases, por lo que eliminarlo de =
la lista podria alterar el tama=C3=B1o y la posicion de las variables. Por =
otro lado seria posible, ya que reservar memoria desde A o desde C como C+A=
, se genera un grupo de variables reservadas en memorias para cada clase in=
cluso si es C+A y llamar a funciones de A lo cual omite C de C+A solo para =
tener a la vista A, podria ser esto una ventaja.<br>Sugiero alguna otra opc=
ion para simular un remplazo de la variable A por C.<br>Si existe algun met=
odo mejor que cumpla con el mismo proposito sin romper con la estructura ba=
sica propuesta aqui entonces mucho mejor.<br><br></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/ef755674-802e-4354-a98d-a782ee90cce2%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/ef755674-802e-4354-a98d-a782ee90cce2=
%40isocpp.org</a>.<br />

------=_Part_1146_100014087.1534015032840--

------=_Part_1145_861094225.1534015032839--

.
