Topic: new featudeclare data that replaces the previous
Author: rmbeer2@gmail.com
Date: Mon, 11 Jun 2018 17:17:53 -0700 (PDT)
Raw View
------=_Part_86037_390491052.1528762673891
Content-Type: multipart/alternative;
boundary="----=_Part_86038_1762764512.1528762673891"
------=_Part_86038_1762764512.1528762673891
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
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 of=
=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, where=
=20
the last A is not used, only C+A, in A it ends up using when the functions=
=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 the=
=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 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 breaking=
=20
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 datos=
=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 totalmente=
=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 clase=
=20
D un C+A,A , donde la ultima A no se usa, solo C+A , en A se termina usando=
=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
};
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 llamar=
=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/adc40bab-d824-440b-99b9-dab0ad6bd482%40isocpp.or=
g.
------=_Part_86038_1762764512.1528762673891
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">We have 2 classes that contain different data sets, one ne=
eds 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 --=
-----> B<br><br>Code:<br>---------------------------------------<br><br>=
class A {<br>public:<br>=C2=A0=C2=A0 =C2=A0A(int z_) : z(z_) {=C2=A0=C2=A0 =
=C2=A0}<br>=C2=A0=C2=A0 =C2=A0int z;<br>};<br><br>class B {<br>public:<br>=
=C2=A0=C2=A0 =C2=A0B() : a(1) { }<br>=C2=A0=C2=A0 =C2=A0void f2() {<br>=C2=
=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0std::cout << "A:" <&l=
t; a.z << std::endl;<br>=C2=A0=C2=A0 =C2=A0}<br>=C2=A0=C2=A0 =C2=A0A =
a;<br>};<br><br>---------------------------------------<br><br>Then you nee=
d to create an inheritance for each class, since you need to cover a new in=
terface layer. Let's call C and D, where C uses the base class A and D =
uses the base class B.<br><br>=C2=A0=C2=A0 member<br>A ---------> B<br>|=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 |<br>|in=
heritance | inheritance<br>|=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0 |<br>v=C2=A0 member=C2=A0=C2=A0=C2=A0 v<br>C --------=
-> D<br><br>Code:<br>---------------------------------------<br><br>clas=
s 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:<b=
r>=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 << "A:" << a.z <&l=
t; std::endl;<br>=C2=A0=C2=A0 =C2=A0}<br>=C2=A0=C2=A0 =C2=A0A a;<br>};<br>c=
lass 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::c=
out << "A:" << a.z << std::endl;<br>=C2=A0=C2=
=A0 =C2=A0}<br>=C2=A0=C2=A0 =C2=A0C a;<br>};<br><br>-----------------------=
----------------<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 c=
all the functions inherited from B, B can only access the data of A that ar=
e totally in disuse, that is, create an instance in D generates in memory a=
variable "a" with C+A, and also a variable "a" with A =
, being in class D a C+A, A, where the last A is not used, only C+A, in A i=
t ends up using when the functions of B. are called.<br>=C2=A0 It is only p=
ossible to create a new virtual type function as the only case to access on=
ly C+A, but this generates junk code and in memory it reserves A as garbage=
:<br><br>Code:<br>---------------------------------------<br>#include <i=
ostream><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 << "A:" << get_C_a().z << s=
td::endl;<br>=C2=A0=C2=A0 =C2=A0}<br>=C2=A0=C2=A0 =C2=A0virtual A const&=
; 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=A0void f2(){<br>=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=
=A0std::cout << "C+A:" << a.z << 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 cons=
t& 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>---------------------------------------<br><br>This would be the best o=
ption, but not the ideal one. Ideally, "C a;" of D replace "=
A a;" of B, in this way D only uses C+A from "C a;" and B on=
ly uses A from "A a;"<br><br>This is my proposal, a keyword like =
'virtual' (or can be any other) in the variable of the same name th=
at is replaced by the variable definition of the base class.<br><br>Por eje=
mplo:<br>Code:<br>---------------------------------------<br>#include <i=
ostream><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 << "A:" << a.z << 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 << "C+A:" << a.z << 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<b=
r>C+A:3<br>A:3<br>*/<br><br>---------------------------------------<br><br>=
well this might not be possible, since compiled the code, the binary code u=
ses the data from an expected position in the variables within the classes,=
so removing it from the list could alter the size and position of the vari=
ables. On the other hand it would be possible, since reserving memory from =
A or from C as C+A, generates a group of variables reserved in memories for=
each class even if it is C+A and calls functions of A which omits C of C+A=
Just to have A in view, this could be an advantage.<br>I suggest some othe=
r option to simulate a replacement of variable A by C.<br>If there is a bet=
ter method that fulfills the same purpose without breaking with the basic s=
tructure 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=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=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>Tene=
mos 2 clases que contienen distintos conjuntos de datos, uno necesita usar =
las funciones y variables de otra clase, por lo que se incluye como miembro=
apuntando a la otra clase:<br><br>=C2=A0=C2=A0 member<br>A -------> B<b=
r><br>Code:<br>---------------------------------------<br><br>class A {<br>=
public:<br>=C2=A0=C2=A0 =C2=A0A(int z_) : z(z_) {=C2=A0=C2=A0 =C2=A0}<br>=
=C2=A0=C2=A0 =C2=A0int z;<br>};<br><br>class B {<br>public:<br>=C2=A0=C2=A0=
=C2=A0B() : a(1) { }<br>=C2=A0=C2=A0 =C2=A0void f2() {<br>=C2=A0=C2=A0 =C2=
=A0=C2=A0=C2=A0 =C2=A0std::cout << "A:" << a.z <&l=
t; std::endl;<br>=C2=A0=C2=A0 =C2=A0}<br>=C2=A0=C2=A0 =C2=A0A a;<br>};<br><=
br>---------------------------------------<br><br>Luego se necesita crear u=
na herencia para cada clase, ya que necesita cubrir una nueva capa de inter=
faz. Llamemos C y D, donde C usa la clase base A y D usa la clase base B.<b=
r><br>=C2=A0=C2=A0 member<br>A ---------> 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 ---------> D<br><br>Code:<br>--=
-------------------------------------<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 << "A:" << a.z << 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 << "A:" =
<< a.z << std::endl;<br>=C2=A0=C2=A0 =C2=A0}<br>=C2=A0=C2=A0 =
=C2=A0C a;<br>};<br><br>---------------------------------------<br><br>=C2=
=A0 Aqui donde aparecen los problemas, si creas B puedes acceder a los dato=
s de A con las funciones de B. Pero si creas D, accedes a los datos de C+A =
con las funciones de D y C, pero tan pronto llamas a las funciones heredada=
s de B, B solo puede acceder a los datos de A que estan totalmente en desus=
o, es decir, crear una instancia en D genera en la memoria una variable &qu=
ot;a" con C+A, y tambien una variable "a" con A, siendo en l=
a clase D un C+A,A , donde la ultima A no se usa, solo C+A , en A se termin=
a usando cuando se llama a las funciones de B.<br>=C2=A0=C2=A0 =C2=A0Solo e=
s posible crear una nueva funcion tipo virtual como unico caso para acceder=
solamente a C+A, pero esto genera codigo basura y en la memoria se reserva=
A como basura:<br><br>Code:<br>---------------------------------------<br>=
#include <iostream><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 << "A:" << get_C_a=
().z << std::endl;<br>=C2=A0=C2=A0 =C2=A0}<br>=C2=A0=C2=A0 =C2=A0virt=
ual A const& 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=A0void f2(){<br>=C2=A0=C2=A0 =C2=
=A0=C2=A0=C2=A0 =C2=A0std::cout << "C+A:" << a.z <=
< 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& 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.f=
2();<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>---------------------------------------<br><br>Esta se=
ria la mejor opcion, pero no la ideal. Lo ideal es que "C a;" de =
D remplace a "A a;" de B, de esta forma D solo usa C+A de "C=
a;" y B solo usa A de "A a;"<br><br>Esta es mi propuesta, u=
na palabra clave como 'virtual' (o puede ser cualquier otra) en la =
variable del mismo nombre que se remplace a la definicion de variable de la=
clase base.<br><br>Por ejemplo:<br>Code:<br>------------------------------=
---------<br>#include <iostream><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 << "A:" &l=
t;< a.z << 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>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 << "C+A:&qu=
ot; << a.z << 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; // U=
se 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>-------------------=
--------------------<br><br>bien esto podria no ser posible, ya que compila=
do el codigo, el codigo binario utiliza los datos desde una posicion espera=
da 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 lad=
o seria posible, ya que reservar memoria desde A o desde C como C+A, se gen=
era un grupo de variables reservadas en memorias para cada clase incluso 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 opcion para=
simular un remplazo de la variable A por C.<br>Si existe algun metodo mejo=
r que cumpla con el mismo proposito sin romper con la estructura basica pro=
puesta aqui entonces mucho mejor.<br><br></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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/adc40bab-d824-440b-99b9-dab0ad6bd482%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/adc40bab-d824-440b-99b9-dab0ad6bd482=
%40isocpp.org</a>.<br />
------=_Part_86038_1762764512.1528762673891--
------=_Part_86037_390491052.1528762673891--
.