Topic: new featudeclare data that replaces the
Author: mihailnajdenov@gmail.com
Date: Tue, 12 Jun 2018 00:28:30 -0700 (PDT)
Raw View
------=_Part_97792_254518234.1528788510279
Content-Type: multipart/alternative;
boundary="----=_Part_97793_1441088912.1528788510279"
------=_Part_97793_1441088912.1528788510279
Content-Type: text/plain; charset="UTF-8"
*Solution 2*
template<class T>
class B {
public:
B(int i=1) : a(i) { }
void f2() {
std::cout << "A:" << a.z << std::endl;
}
// virtual A a; // Use A only from B
T a;
};
class D : public B<C> {
public:
D() : B<C>(3) { }
void f2(){
std::cout << "C+A:" << a.z << std::endl;
B::f2();
}
// virtual C a; // Use C+A only from D
};
*Solution 3*
class B
{
public:
B(A* a_) : a(a_) { }
B() : a(new A(1)) { }
void f2() {
std::cout << "A:" << a->z << std::endl;
}
// virtual A a; // Use A only from B
std::unique_ptr<A> a;
};
class D : public B
{
public:
D() : B(new C(3)) { }
void f2(){
std::cout << "C+A:" << a->z << std::endl;
B::f2();
}
// virtual C a; // Use C+A only from D
};
*Solution 4*
Develop in terms of interfaces only
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/bebc25db-8a70-4f45-9694-f5e517dccbce%40isocpp.org.
------=_Part_97793_1441088912.1528788510279
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div><b><font face=3D"arial,sans-serif">Solution 2</font><=
/b></div><div><font face=3D"courier new,monospace"><b></b><font face=3D"ari=
al,sans-serif"></font><br></font></div><div><font face=3D"courier new,monos=
pace"><br>template<class T><br>class B {<br>public:<br>=C2=A0=C2=A0=
=C2=A0 B(int i=3D1) : a(i) { }<br>=C2=A0=C2=A0=C2=A0 void f2() {<br>=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 std::cout << "A:" <=
< a.z << std::endl;<br>=C2=A0=C2=A0=C2=A0 }<br>//=C2=A0=C2=A0=C2=
=A0 virtual A a; // Use A only from B<br>=C2=A0=C2=A0=C2=A0 T a;<br>};</fon=
t></div><div><font face=3D"courier new,monospace">class D : public B<C&g=
t; {<br>public:<br>=C2=A0=C2=A0=C2=A0 D() : B<C>(3) { }<br>=C2=A0=C2=
=A0=C2=A0 void f2(){<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 std::cou=
t << "C+A:" << a.z << std::endl;<br>=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 B::f2();<br>=C2=A0=C2=A0=C2=A0 }<br>//=C2=
=A0=C2=A0=C2=A0 virtual C a; // Use C+A only from D<br>};</font></div><div>=
<font face=3D"courier new,monospace"><br></font></div><div><font face=3D"ar=
ial,sans-serif"></font><b></b><br></div><div><font face=3D"arial,sans-serif=
"><b>Solution 3</b></font></div><div><font face=3D"courier new,monospace"><=
br></font></div><font face=3D"courier new,monospace"><br><div>class B=C2=A0=
</div><div>{<br></div>public:<br>=C2=A0 B(A* a_) : a(a_) { }<br>=C2=A0 B() =
: a(new A(1)) { }<br>=C2=A0 void f2() {<br>=C2=A0=C2=A0 std::cout << =
"A:" << a->z << std::endl;<br>=C2=A0 }<br>// vi=
rtual A a; // Use A only from B<br>=C2=A0 =C2=A0 std::unique_ptr<A> a=
;<br><div>};</div><div><br></div><div>class D : public B=C2=A0</div><div>{<=
br></div>public:<br>=C2=A0 D() : B(new C(3)) { }<br>=C2=A0 void f2(){<br>=
=C2=A0 =C2=A0 std::cout << "C+A:" << a->z <<=
std::endl;<br>=C2=A0 =C2=A0 B::f2();<br>=C2=A0 }<br>// virtual C a; // =
Use C+A only from D<br>};</font><div><font face=3D"arial,sans-serif"><b><br=
></b></font></div><div><font face=3D"arial,sans-serif"><b><br></b></font></=
div><div><font face=3D"arial,sans-serif"><b>Solution 4</b></font></div><div=
><font face=3D"courier new,monospace"><font face=3D"arial,sans-serif"></fon=
t><b></b><br></font></div><div><font face=3D"arial,sans-serif">Develop in t=
erms of interfaces only</font></div><div><font face=3D"arial,sans-serif"><b=
r></font></div><div><font face=3D"arial,sans-serif"></font><br></div></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/bebc25db-8a70-4f45-9694-f5e517dccbce%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/bebc25db-8a70-4f45-9694-f5e517dccbce=
%40isocpp.org</a>.<br />
------=_Part_97793_1441088912.1528788510279--
------=_Part_97792_254518234.1528788510279--
.
Author: rmbeer2@gmail.com
Date: Thu, 14 Jun 2018 16:37:57 -0700 (PDT)
Raw View
------=_Part_5373_748019684.1529019477671
Content-Type: multipart/alternative;
boundary="----=_Part_5374_1386542103.1529019477671"
------=_Part_5374_1386542103.1529019477671
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
It seems that nobody else says it...
With template you just broke the structure of the classes, and did not even=
=20
take into account the class "A a;". And what is the last answer? It does=20
not explain anything. In short, no answer works...
Parece que nadie mas lo comenta...
Con template simplemente acabaste de romper con la estructura de las=20
clases, y ni siquiera lo tomaste en cuenta la clase "A a;". Y en que=20
consiste la ultima respuesta? No explica nada. En fin, ninguna respuesta=20
sirve...
El martes, 12 de junio de 2018, 4:28:30 (UTC-3), mihailn...@gmail.com=20
escribi=C3=B3:
>
> *Solution 2*
>
>
> template<class T>
> class B {
> public:
> B(int i=3D1) : a(i) { }
> void f2() {
> std::cout << "A:" << a.z << std::endl;
> }
> // virtual A a; // Use A only from B
> T a;
> };
> class D : public B<C> {
> public:
> D() : B<C>(3) { }
> void f2(){
> std::cout << "C+A:" << a.z << std::endl;
> B::f2();
> }
> // virtual C a; // Use C+A only from D
> };
>
>
> *Solution 3*
>
>
> class B=20
> {
> public:
> B(A* a_) : a(a_) { }
> B() : a(new A(1)) { }
> void f2() {
> std::cout << "A:" << a->z << std::endl;
> }
> // virtual A a; // Use A only from B
> std::unique_ptr<A> a;
> };
>
> class D : public B=20
> {
> public:
> D() : B(new C(3)) { }
> void f2(){
> std::cout << "C+A:" << a->z << std::endl;
> B::f2();
> }
> // virtual C a; // Use C+A only from D
> };
>
>
> *Solution 4*
>
> Develop in terms of interfaces only
>
>
>
--=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/1263c0e2-9de4-4859-ba99-12fb770c93ba%40isocpp.or=
g.
------=_Part_5374_1386542103.1529019477671
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div>It seems that nobody else says it...<br></div><div>Wi=
th template you just broke the structure of the classes, and did not even t=
ake into account the class "A a;". And what is the last answer? I=
t does not explain anything. In short, no answer works...<br></div><div><br=
></div><div>Parece que nadie mas lo comenta...</div><div>Con template simpl=
emente acabaste de romper con la estructura de las clases, y ni siquiera lo=
tomaste en cuenta la clase "A a;". Y en que consiste la ultima r=
espuesta? No explica nada. En fin, ninguna respuesta sirve...<br></div><br>=
El martes, 12 de junio de 2018, 4:28:30 (UTC-3), mihailn...@gmail.com escri=
bi=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"><div=
><b><font face=3D"arial,sans-serif">Solution 2</font></b></div><div><font f=
ace=3D"courier new,monospace"><b></b><font face=3D"arial,sans-serif"></font=
><br></font></div><div><font face=3D"courier new,monospace"><br>template<=
;class T><br>class B {<br>public:<br>=C2=A0=C2=A0=C2=A0 B(int i=3D1) : a=
(i) { }<br>=C2=A0=C2=A0=C2=A0 void f2() {<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0 std::cout << "A:" << a.z << std::e=
ndl;<br>=C2=A0=C2=A0=C2=A0 }<br>//=C2=A0=C2=A0=C2=A0 virtual A a; // Use A =
only from B<br>=C2=A0=C2=A0=C2=A0 T a;<br>};</font></div><div><font face=3D=
"courier new,monospace">class D : public B<C> {<br>public:<br>=C2=A0=
=C2=A0=C2=A0 D() : B<C>(3) { }<br>=C2=A0=C2=A0=C2=A0 void f2(){<br>=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 std::cout << "C+A:&qu=
ot; << a.z << std::endl;<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0 B::f2();<br>=C2=A0=C2=A0=C2=A0 }<br>//=C2=A0=C2=A0=C2=A0 virtual =
C a; // Use C+A only from D<br>};</font></div><div><font face=3D"courier ne=
w,monospace"><br></font></div><div><font face=3D"arial,sans-serif"></font><=
b></b><br></div><div><font face=3D"arial,sans-serif"><b>Solution 3</b></fon=
t></div><div><font face=3D"courier new,monospace"><br></font></div><font fa=
ce=3D"courier new,monospace"><br><div>class B=C2=A0</div><div>{<br></div>pu=
blic:<br>=C2=A0 B(A* a_) : a(a_) { }<br>=C2=A0 B() : a(new A(1)) { }<br>=C2=
=A0 void f2() {<br>=C2=A0=C2=A0 std::cout << "A:" << =
a->z << std::endl;<br>=C2=A0 }<br>// virtual A a; // Use A only=
from B<br>=C2=A0 =C2=A0 std::unique_ptr<A> a;<br><div>};</div><div><=
br></div><div>class D : public B=C2=A0</div><div>{<br></div>public:<br>=C2=
=A0 D() : B(new C(3)) { }<br>=C2=A0 void f2(){<br>=C2=A0 =C2=A0 std::cout &=
lt;< "C+A:" << a->z << std::endl;<br>=C2=A0 =C2=
=A0 B::f2();<br>=C2=A0 }<br>// virtual C a; // Use C+A only from D<br>};=
</font><div><font face=3D"arial,sans-serif"><b><br></b></font></div><div><f=
ont face=3D"arial,sans-serif"><b><br></b></font></div><div><font face=3D"ar=
ial,sans-serif"><b>Solution 4</b></font></div><div><font face=3D"courier ne=
w,monospace"><font face=3D"arial,sans-serif"></font><b></b><br></font></div=
><div><font face=3D"arial,sans-serif">Develop in terms of interfaces only</=
font></div><div><font face=3D"arial,sans-serif"><br></font></div><div><font=
face=3D"arial,sans-serif"></font><br></div></div></blockquote></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/1263c0e2-9de4-4859-ba99-12fb770c93ba%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/1263c0e2-9de4-4859-ba99-12fb770c93ba=
%40isocpp.org</a>.<br />
------=_Part_5374_1386542103.1529019477671--
------=_Part_5373_748019684.1529019477671--
.
Author: mihailnajdenov@gmail.com
Date: Fri, 15 Jun 2018 01:55:43 -0700 (PDT)
Raw View
------=_Part_6846_81750997.1529052943523
Content-Type: multipart/alternative;
boundary="----=_Part_6847_1679991565.1529052943523"
------=_Part_6847_1679991565.1529052943523
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
From what you presented you want to (literarily) override data so it is not=
=20
duplicated. And there are many ways to do that, both statically or=20
dynamically.=20
I forgot Variant is also an option.
The last solution is to simply not let data duplications happen by working=
=20
with abstract classes.=20
Alternatives aside, you can try implementing your solution with boilerplate=
=20
code and see what is not there, if any, that make it impossible and suggest=
=20
something that might be useful outside that case as well,
and if everything is there, then you can suggest a library solution.
On Friday, June 15, 2018 at 2:37:57 AM UTC+3, rmb...@gmail.com wrote:
>
> It seems that nobody else says it...
> With template you just broke the structure of the classes, and did not=20
> even take into account the class "A a;". And what is the last answer? It=
=20
> does not explain anything. In short, no answer works...
>
> Parece que nadie mas lo comenta...
> Con template simplemente acabaste de romper con la estructura de las=20
> clases, y ni siquiera lo tomaste en cuenta la clase "A a;". Y en que=20
> consiste la ultima respuesta? No explica nada. En fin, ninguna respuesta=
=20
> sirve...
>
> El martes, 12 de junio de 2018, 4:28:30 (UTC-3), mihailn...@gmail.com=20
> escribi=C3=B3:
>>
>> *Solution 2*
>>
>>
>> template<class T>
>> class B {
>> public:
>> B(int i=3D1) : a(i) { }
>> void f2() {
>> std::cout << "A:" << a.z << std::endl;
>> }
>> // virtual A a; // Use A only from B
>> T a;
>> };
>> class D : public B<C> {
>> public:
>> D() : B<C>(3) { }
>> void f2(){
>> std::cout << "C+A:" << a.z << std::endl;
>> B::f2();
>> }
>> // virtual C a; // Use C+A only from D
>> };
>>
>>
>> *Solution 3*
>>
>>
>> class B=20
>> {
>> public:
>> B(A* a_) : a(a_) { }
>> B() : a(new A(1)) { }
>> void f2() {
>> std::cout << "A:" << a->z << std::endl;
>> }
>> // virtual A a; // Use A only from B
>> std::unique_ptr<A> a;
>> };
>>
>> class D : public B=20
>> {
>> public:
>> D() : B(new C(3)) { }
>> void f2(){
>> std::cout << "C+A:" << a->z << std::endl;
>> B::f2();
>> }
>> // virtual C a; // Use C+A only from D
>> };
>>
>>
>> *Solution 4*
>>
>> Develop in terms of interfaces only
>>
>>
>>
--=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/503c3169-7bda-438b-ac1e-a6a7347b053f%40isocpp.or=
g.
------=_Part_6847_1679991565.1529052943523
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div>From what you presented you want to (literarily) over=
ride data so it is not duplicated. And there are many ways to do that, both=
statically or dynamically.=C2=A0</div><div><br></div><div>I forgot Variant=
is also an option.</div><div><br></div><div>The last solution is to simply=
not let data duplications happen by working with abstract classes.=C2=A0</=
div><div><br></div><div><br></div><div>Alternatives aside, you can try impl=
ementing your solution with boilerplate code and see what is not there, if =
any, that make it impossible and suggest something that might be useful out=
side that case as well,</div><div>=C2=A0and if everything is there, then yo=
u can suggest a library solution.</div><div><br></div><div><br></div><br>On=
Friday, June 15, 2018 at 2:37:57 AM UTC+3, rmb...@gmail.com wrote:<blockqu=
ote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left=
: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><div>It seems that no=
body else says it...<br></div><div>With template you just broke the structu=
re of the classes, and did not even take into account the class "A a;&=
quot;. And what is the last answer? It does not explain anything. In short,=
no answer works...<br></div><div><br></div><div>Parece que nadie mas lo co=
menta...</div><div>Con template simplemente acabaste de romper con la estru=
ctura de las clases, y ni siquiera lo tomaste en cuenta la clase "A a;=
". Y en que consiste la ultima respuesta? No explica nada. En fin, nin=
guna respuesta sirve...<br></div><br>El martes, 12 de junio de 2018, 4:28:3=
0 (UTC-3), <a>mihailn...@gmail.com</a> escribi=C3=B3:<blockquote class=3D"g=
mail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;=
padding-left:1ex"><div dir=3D"ltr"><div><b><font face=3D"arial,sans-serif">=
Solution 2</font></b></div><div><font face=3D"courier new,monospace"><b></b=
><font face=3D"arial,sans-serif"></font><br></font></div><div><font face=3D=
"courier new,monospace"><br>template<class T><br>class B {<br>public:=
<br>=C2=A0=C2=A0=C2=A0 B(int i=3D1) : a(i) { }<br>=C2=A0=C2=A0=C2=A0 void f=
2() {<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 std::cout << &quo=
t;A:" << a.z << std::endl;<br>=C2=A0=C2=A0=C2=A0 }<br>//=
=C2=A0=C2=A0=C2=A0 virtual A a; // Use A only from B<br>=C2=A0=C2=A0=C2=A0 =
T a;<br>};</font></div><div><font face=3D"courier new,monospace">class D : =
public B<C> {<br>public:<br>=C2=A0=C2=A0=C2=A0 D() : B<C>(3) { =
}<br>=C2=A0=C2=A0=C2=A0 void f2(){<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0 std::cout << "C+A:" << a.z << std::endl;=
<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 B::f2();<br>=C2=A0=C2=A0=C2=
=A0 }<br>//=C2=A0=C2=A0=C2=A0 virtual C a; // Use C+A only from D<br>};</fo=
nt></div><div><font face=3D"courier new,monospace"><br></font></div><div><f=
ont face=3D"arial,sans-serif"></font><b></b><br></div><div><font face=3D"ar=
ial,sans-serif"><b>Solution 3</b></font></div><div><font face=3D"courier ne=
w,monospace"><br></font></div><font face=3D"courier new,monospace"><br><div=
>class B=C2=A0</div><div>{<br></div>public:<br>=C2=A0 B(A* a_) : a(a_) { }<=
br>=C2=A0 B() : a(new A(1)) { }<br>=C2=A0 void f2() {<br>=C2=A0=C2=A0 std::=
cout << "A:" << a->z << std::endl;<br>=C2=A0=
}<br>// virtual A a; // Use A only from B<br>=C2=A0 =C2=A0 std::unique_=
ptr<A> a;<br><div>};</div><div><br></div><div>class D : public B=C2=
=A0</div><div>{<br></div>public:<br>=C2=A0 D() : B(new C(3)) { }<br>=C2=A0 =
void f2(){<br>=C2=A0 =C2=A0 std::cout << "C+A:" << a-=
>z << std::endl;<br>=C2=A0 =C2=A0 B::f2();<br>=C2=A0 }<br>// vi=
rtual C a; // Use C+A only from D<br>};</font><div><font face=3D"arial,sans=
-serif"><b><br></b></font></div><div><font face=3D"arial,sans-serif"><b><br=
></b></font></div><div><font face=3D"arial,sans-serif"><b>Solution 4</b></f=
ont></div><div><font face=3D"courier new,monospace"><font face=3D"arial,san=
s-serif"></font><b></b><br></font></div><div><font face=3D"arial,sans-serif=
">Develop in terms of interfaces only</font></div><div><font face=3D"arial,=
sans-serif"><br></font></div><div><font face=3D"arial,sans-serif"></font><b=
r></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" 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/503c3169-7bda-438b-ac1e-a6a7347b053f%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/503c3169-7bda-438b-ac1e-a6a7347b053f=
%40isocpp.org</a>.<br />
------=_Part_6847_1679991565.1529052943523--
------=_Part_6846_81750997.1529052943523--
.
Author: rmbeer2@gmail.com
Date: Fri, 13 Jul 2018 05:36:07 -0700 (PDT)
Raw View
------=_Part_113519_1789480809.1531485367823
Content-Type: multipart/alternative;
boundary="----=_Part_113520_840654334.1531485367823"
------=_Part_113520_840654334.1531485367823
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Is this really a C ++ standard language community? So far I have only=20
received 2 stupid answers and a huge silence after waiting a lot of time. I=
=20
expected more serious participation from the community as to how to solve=
=20
this problem, because evidently with the current language you can not.
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D
Realmente esta es una comunidad de lenguaje estandar C++? Hasta ahora solo=
=20
he recibido 2 respuestas estupidas y un silencio enorme tras esperar un=20
monton de tiempo. Esperaba una participacion mas seria por parte de la=20
comunidad como pensar en como resolver este problema, porque evidentemente=
=20
con el lenguaje actual no se puede.
El viernes, 15 de junio de 2018, 5:55:43 (UTC-3), mihailn...@gmail.com=20
escribi=C3=B3:
>
> From what you presented you want to (literarily) override data so it is=
=20
> not duplicated. And there are many ways to do that, both statically or=20
> dynamically.=20
>
> I forgot Variant is also an option.
>
> The last solution is to simply not let data duplications happen by workin=
g=20
> with abstract classes.=20
>
>
> Alternatives aside, you can try implementing your solution with=20
> boilerplate code and see what is not there, if any, that make it impossib=
le=20
> and suggest something that might be useful outside that case as well,
> and if everything is there, then you can suggest a library solution.
>
>
>
> On Friday, June 15, 2018 at 2:37:57 AM UTC+3, rmb...@gmail.com wrote:
>>
>> It seems that nobody else says it...
>> With template you just broke the structure of the classes, and did not=
=20
>> even take into account the class "A a;". And what is the last answer? It=
=20
>> does not explain anything. In short, no answer works...
>>
>> Parece que nadie mas lo comenta...
>> Con template simplemente acabaste de romper con la estructura de las=20
>> clases, y ni siquiera lo tomaste en cuenta la clase "A a;". Y en que=20
>> consiste la ultima respuesta? No explica nada. En fin, ninguna respuesta=
=20
>> sirve...
>>
>> El martes, 12 de junio de 2018, 4:28:30 (UTC-3), mihailn...@gmail.com=20
>> escribi=C3=B3:
>>>
>>> *Solution 2*
>>>
>>>
>>> template<class T>
>>> class B {
>>> public:
>>> B(int i=3D1) : a(i) { }
>>> void f2() {
>>> std::cout << "A:" << a.z << std::endl;
>>> }
>>> // virtual A a; // Use A only from B
>>> T a;
>>> };
>>> class D : public B<C> {
>>> public:
>>> D() : B<C>(3) { }
>>> void f2(){
>>> std::cout << "C+A:" << a.z << std::endl;
>>> B::f2();
>>> }
>>> // virtual C a; // Use C+A only from D
>>> };
>>>
>>>
>>> *Solution 3*
>>>
>>>
>>> class B=20
>>> {
>>> public:
>>> B(A* a_) : a(a_) { }
>>> B() : a(new A(1)) { }
>>> void f2() {
>>> std::cout << "A:" << a->z << std::endl;
>>> }
>>> // virtual A a; // Use A only from B
>>> std::unique_ptr<A> a;
>>> };
>>>
>>> class D : public B=20
>>> {
>>> public:
>>> D() : B(new C(3)) { }
>>> void f2(){
>>> std::cout << "C+A:" << a->z << std::endl;
>>> B::f2();
>>> }
>>> // virtual C a; // Use C+A only from D
>>> };
>>>
>>>
>>> *Solution 4*
>>>
>>> Develop in terms of interfaces only
>>>
>>>
>>>
--=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/44ff0208-9ba9-4765-9983-e71125ed88fa%40isocpp.or=
g.
------=_Part_113520_840654334.1531485367823
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Is this really a C ++ standard language community? So far =
I have only received 2 stupid answers and a huge silence after waiting a lo=
t of time. I expected more serious participation from the community as to h=
ow to solve this problem, because evidently with the current language you c=
an not.<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>Realmente esta es una comunidad de le=
nguaje estandar C++? Hasta ahora solo he recibido 2 respuestas estupidas y =
un silencio enorme tras esperar un monton de tiempo. Esperaba una participa=
cion mas seria por parte de la comunidad como pensar en como resolver este =
problema, porque evidentemente con el lenguaje actual no se puede.<br><br><=
br>El viernes, 15 de junio de 2018, 5:55:43 (UTC-3), mihailn...@gmail.com e=
scribi=C3=B3:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-le=
ft: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr">=
<div>From what you presented you want to (literarily) override data so it i=
s not duplicated. And there are many ways to do that, both statically or dy=
namically.=C2=A0</div><div><br></div><div>I forgot Variant is also an optio=
n.</div><div><br></div><div>The last solution is to simply not let data dup=
lications happen by working with abstract classes.=C2=A0</div><div><br></di=
v><div><br></div><div>Alternatives aside, you can try implementing your sol=
ution with boilerplate code and see what is not there, if any, that make it=
impossible and suggest something that might be useful outside that case as=
well,</div><div>=C2=A0and if everything is there, then you can suggest a l=
ibrary solution.</div><div><br></div><div><br></div><br>On Friday, June 15,=
2018 at 2:37:57 AM UTC+3, <a>rmb...@gmail.com</a> wrote:<blockquote class=
=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc s=
olid;padding-left:1ex"><div dir=3D"ltr"><div>It seems that nobody else says=
it...<br></div><div>With template you just broke the structure of the clas=
ses, and did not even take into account the class "A a;". And wha=
t is the last answer? It does not explain anything. In short, no answer wor=
ks...<br></div><div><br></div><div>Parece que nadie mas lo comenta...</div>=
<div>Con template simplemente acabaste de romper con la estructura de las c=
lases, y ni siquiera lo tomaste en cuenta la clase "A a;". Y en q=
ue consiste la ultima respuesta? No explica nada. En fin, ninguna respuesta=
sirve...<br></div><br>El martes, 12 de junio de 2018, 4:28:30 (UTC-3), <a>=
mihailn...@gmail.com</a> escribi=C3=B3:<blockquote class=3D"gmail_quote" st=
yle=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1=
ex"><div dir=3D"ltr"><div><b><font face=3D"arial,sans-serif">Solution 2</fo=
nt></b></div><div><font face=3D"courier new,monospace"><b></b><font face=3D=
"arial,sans-serif"></font><br></font></div><div><font face=3D"courier new,m=
onospace"><br>template<class T><br>class B {<br>public:<br>=C2=A0=C2=
=A0=C2=A0 B(int i=3D1) : a(i) { }<br>=C2=A0=C2=A0=C2=A0 void f2() {<br>=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 std::cout << "A:" &=
lt;< a.z << std::endl;<br>=C2=A0=C2=A0=C2=A0 }<br>//=C2=A0=C2=A0=
=C2=A0 virtual A a; // Use A only from B<br>=C2=A0=C2=A0=C2=A0 T a;<br>};</=
font></div><div><font face=3D"courier new,monospace">class D : public B<=
C> {<br>public:<br>=C2=A0=C2=A0=C2=A0 D() : B<C>(3) { }<br>=C2=A0=
=C2=A0=C2=A0 void f2(){<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 std::=
cout << "C+A:" << a.z << std::endl;<br>=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 B::f2();<br>=C2=A0=C2=A0=C2=A0 }<br>//=
=C2=A0=C2=A0=C2=A0 virtual C a; // Use C+A only from D<br>};</font></div><d=
iv><font face=3D"courier new,monospace"><br></font></div><div><font face=3D=
"arial,sans-serif"></font><b></b><br></div><div><font face=3D"arial,sans-se=
rif"><b>Solution 3</b></font></div><div><font face=3D"courier new,monospace=
"><br></font></div><font face=3D"courier new,monospace"><br><div>class B=C2=
=A0</div><div>{<br></div>public:<br>=C2=A0 B(A* a_) : a(a_) { }<br>=C2=A0 B=
() : a(new A(1)) { }<br>=C2=A0 void f2() {<br>=C2=A0=C2=A0 std::cout <&l=
t; "A:" << a->z << std::endl;<br>=C2=A0 }<br>// =
virtual A a; // Use A only from B<br>=C2=A0 =C2=A0 std::unique_ptr<A>=
; a;<br><div>};</div><div><br></div><div>class D : public B=C2=A0</div><div=
>{<br></div>public:<br>=C2=A0 D() : B(new C(3)) { }<br>=C2=A0 void f2(){<br=
>=C2=A0 =C2=A0 std::cout << "C+A:" << a->z <<=
; std::endl;<br>=C2=A0 =C2=A0 B::f2();<br>=C2=A0 }<br>// virtual C a; //=
Use C+A only from D<br>};</font><div><font face=3D"arial,sans-serif"><b><b=
r></b></font></div><div><font face=3D"arial,sans-serif"><b><br></b></font><=
/div><div><font face=3D"arial,sans-serif"><b>Solution 4</b></font></div><di=
v><font face=3D"courier new,monospace"><font face=3D"arial,sans-serif"></fo=
nt><b></b><br></font></div><div><font face=3D"arial,sans-serif">Develop in =
terms of interfaces only</font></div><div><font face=3D"arial,sans-serif"><=
br></font></div><div><font face=3D"arial,sans-serif"></font><br></div></div=
></blockquote></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" 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/44ff0208-9ba9-4765-9983-e71125ed88fa%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/44ff0208-9ba9-4765-9983-e71125ed88fa=
%40isocpp.org</a>.<br />
------=_Part_113520_840654334.1531485367823--
------=_Part_113519_1789480809.1531485367823--
.
Author: Nicol Bolas <jmckesson@gmail.com>
Date: Fri, 13 Jul 2018 07:09:28 -0700 (PDT)
Raw View
------=_Part_142339_188481673.1531490968483
Content-Type: multipart/alternative;
boundary="----=_Part_142340_576912434.1531490968483"
------=_Part_142340_576912434.1531490968483
Content-Type: text/plain; charset="UTF-8"
On Friday, July 13, 2018 at 8:36:07 AM UTC-4, rmb...@gmail.com wrote:
>
> Is this really a C ++ standard language community? So far I have only
> received 2 stupid answers and a huge silence after waiting a lot of time. I
> expected more serious participation from the community as to how to solve
> this problem, because evidently with the current language you can not.
>
Well... this *isn't* a C++ standard language community. It's a forum for
discussing potential proposals for C++. We're not here to debug problems
with your code; we're here to help refine proposals for the
language/library.
But even viewed from that light, just because you make a proposal doesn't
mean everyone has to comment on it. Not all proposal ideas merit such
commentary.
Maybe the proposal is solving a problem that exists for so few people that
it's not worth standardizing (polymorphic inheritance is rather out of
vogue in the C++ community, unless it is absolutely necessary). Maybe the
existing commentary (change your design, not the language) is seen by
everyone else as sufficient commentary on the proposal. Or whatever.
Personally, I would say that your problem is so specific and special-case
that it's not worth solving in the language. Encountering this problem
requires multiple inheritance of the same base class type. This is not
something people do a lot. Or at least, not when they expect one base class
to be able to manipulate a different base class's subobjects. So this is
not a general usability problem.
Furthermore, I feel this problem is best avoided by design. That is, you
seem to have some class relationships that do not really mesh with what C++
inheritance is *supposed* to mean. C++ inheritance can be complex, and
that's fine, but sometimes people use it improperly. And code like this
suggests improper use of the feature. There is probably a better way to
express the relationship between these subobjects than inheritance.
But this is not a debugging/redesign forum.
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/484a7da1-dbbe-4de5-892d-9f76d11e2e5f%40isocpp.org.
------=_Part_142340_576912434.1531490968483
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Friday, July 13, 2018 at 8:36:07 AM UTC-4, rmb...@gmail=
..com wrote:<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">Is=
this really a C ++ standard language community? So far I have only receive=
d 2 stupid answers and a huge silence after waiting a lot of time. I expect=
ed more serious participation from the community as to how to solve this pr=
oblem, because evidently with the current language you can not.<br></div></=
blockquote><div><br></div><div>Well... this <i>isn't</i> a C++ standard=
language community. It's a forum for discussing potential proposals fo=
r C++. We're not here to debug problems with your code; we're here =
to help refine proposals for the language/library.</div><div><br></div><div=
>But even viewed from that light, just because you make a proposal doesn=
9;t mean everyone has to comment on it. Not all proposal ideas merit such c=
ommentary.</div><div><br></div><div>Maybe the proposal is solving a problem=
that exists for so few people that it's not worth standardizing (polym=
orphic inheritance is rather out of vogue in the C++ community, unless it i=
s absolutely necessary). Maybe the existing commentary (change your design,=
not the language) is seen by everyone else as sufficient commentary on the=
proposal. Or whatever.</div><div><br></div><div>Personally, I would say th=
at your problem is so specific and special-case that it's not worth sol=
ving in the language. Encountering this problem requires multiple inheritan=
ce of the same base class type. This is not something people do a lot. Or a=
t least, not when they expect one base class to be able to manipulate a dif=
ferent base class's subobjects. So this is not a general usability prob=
lem.</div><div><br></div><div>Furthermore, I feel this problem is best avoi=
ded by design. That is, you seem to have some class relationships that do n=
ot really mesh with what C++ inheritance is <i>supposed</i> to mean. C++ in=
heritance can be complex, and that's fine, but sometimes people use it =
improperly. And code like this suggests improper use of the feature. There =
is probably a better way to express the relationship between these subobjec=
ts than inheritance.</div><div><br></div><div>But this is not a debugging/r=
edesign forum.<br></div></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/484a7da1-dbbe-4de5-892d-9f76d11e2e5f%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/484a7da1-dbbe-4de5-892d-9f76d11e2e5f=
%40isocpp.org</a>.<br />
------=_Part_142340_576912434.1531490968483--
------=_Part_142339_188481673.1531490968483--
.
Author: cppljevans@gmail.com
Date: Wed, 18 Jul 2018 03:04:33 -0700 (PDT)
Raw View
------=_Part_11541_1987043502.1531908273240
Content-Type: multipart/alternative;
boundary="----=_Part_11542_1573015084.1531908273240"
------=_Part_11542_1573015084.1531908273240
Content-Type: text/plain; charset="UTF-8"
On Monday, June 11, 2018 at 7:17:54 PM UTC-5, rmb...@gmail.com wrote:
>
> We have 2 classes that contain different data sets, one needs to use the
> functions and variables of another class, so it is included as a member
> pointing to the other class:
>
> member
> A -------> B
>
> Code:
> ---------------------------------------
>
> class A {
> public:
> A(int z_) : z(z_) { }
> int z;
> };
>
> class B {
> public:
> B() : a(1) { }
> void f2() {
> std::cout << "A:" << a.z << std::endl;
> }
> A a;
> };
>
> ---------------------------------------
>
> Then you need to create an inheritance for each class, since you need to
> cover a new interface layer. Let's call C and D, where C uses the base
> class A and D uses the base class B.
>
> member
> A ---------> B
> | |
> |inheritance | inheritance
> | |
> v member v
> C ---------> D
>
> Code:
> ---------------------------------------
>
> class A {
> public:
> A(int z_) : z(z_) { }
> int z;
> };
> class C: public A {
> public:
> C(int y_) : y(y_), A(y_) { }
> long y;
> };
>
> class B {
> public:
> B() : a(1) { }
> void f2() {
> std::cout << "A:" << a.z << std::endl;
> }
> A a;
> };
> class D: public B {
> public:
> B() : a(3) { }
> void f2() {
> std::cout << "A:" << a.z << std::endl;
> }
> C a;
> };
>
> ---------------------------------------
>
> Here where the problems appear, if you create B you can access the data of
> A with the functions of B. But if you create D, you access the data of C+A
> with the functions of D and C, but as soon as you call the functions
> inherited from B, B can only access the data of A that are totally in
> disuse, that is, create an instance in D generates in memory a variable "a"
> with C+A, and also a variable "a" with A , being in class D a C+A, A, where
> the last A is not used, only C+A, in A it ends up using when the functions
> of B. are called.
> It is only possible to create a new virtual type function as the only
> case to access only C+A, but this generates junk code and in memory it
> reserves A as garbage:
>
> Code:
> ---------------------------------------
> #include <iostream>
>
> class A {
> public:
> A(int z_) : z(z_) { }
> int z;
> };
>
> class C: public A {
> public:
> C(int z_) : A(z_) { }
> };
>
> class B {
> public:
> B() : a(1) { }
> void f2() {
> std::cout << "A:" << get_C_a().z << std::endl;
> }
> virtual A const& get_C_a() { return a; }
> A a; // Use only from B
> };
>
> class D : public B {
> public:
> D() : a(3) { }
> void f2(){
> std::cout << "C+A:" << a.z << std::endl;
> B::f2();
> }
> C a; // Use C+A only from D
> A const& get_C_a() override { return a; }
> };
>
> int main() {
> B b; D d;
> b.f2(); d.f2();
> return 0;
> }
>
> /* OUTPUT:
> A:1
> C+A:3
> A:3
> */
>
> ---------------------------------------
>
> This would be the best option, but not the ideal one. Ideally, "C a;" of D
> replace "A a;" of B, in this way D only uses C+A from "C a;" and B only
> uses A from "A a;"
>
> This is my proposal, a keyword like 'virtual' (or can be any other) in the
> variable of the same name that is replaced by the variable definition of
> the base class.
>
> Por ejemplo:
> Code:
> ---------------------------------------
> #include <iostream>
>
> class A {
> public:
> A(int z_) : z(z_) { }
> int z;
> };
>
> class C: public A {
> public:
> C(int z_) : A(z_) { }
> };
>
> class B {
> public:
> B() : a(1) { }
> void f2() {
> std::cout << "A:" << a.z << std::endl;
> }
> virtual A a; // Use A only from B
> };
>
> class D : public B {
> public:
> D() : a(3) { }
> void f2(){
> std::cout << "C+A:" << a.z << std::endl;
> B::f2();
> }
> virtual C a; // Use C+A only from D
> };
>
> int main() {
> B b; D d;
> b.f2(); d.f2();
> return 0;
> }
>
> /* OUTPUT:
> A:1
> C+A:3
> A:3
> */
>
> ---------------------------------------
>
> well this might not be possible, since compiled the code, the binary code
> uses the data from an expected position in the variables within the
> classes, so removing it from the list could alter the size and position of
> the variables. On the other hand it would be possible, since reserving
> memory from A or from C as C+A, generates a group of variables reserved in
> memories for each class even if it is C+A and calls functions of A which
> omits C of C+A Just to have A in view, this could be an advantage.
> I suggest some other option to simulate a replacement of variable A by C.
> If there is a better method that fulfills the same purpose without
> breaking with the basic structure proposed here then much better.
>
>
> ================================================================================
>
> Tenemos 2 clases que contienen distintos conjuntos de datos, uno necesita
> usar las funciones y variables de otra clase, por lo que se incluye como
> miembro apuntando a la otra clase:
>
> member
> A -------> B
>
> Code:
> ---------------------------------------
>
> class A {
> public:
> A(int z_) : z(z_) { }
> int z;
> };
>
> class B {
> public:
> B() : a(1) { }
> void f2() {
> std::cout << "A:" << a.z << std::endl;
> }
> A a;
> };
>
> ---------------------------------------
>
> Luego se necesita crear una herencia para cada clase, ya que necesita
> cubrir una nueva capa de interfaz. Llamemos C y D, donde C usa la clase
> base A y D usa la clase base B.
>
> member
> A ---------> B
> | |
> |inheritance | inheritance
> | |
> v member v
> C ---------> D
>
> Code:
> ---------------------------------------
>
> class A {
> public:
> A(int z_) : z(z_) { }
> int z;
> };
> class C: public A {
> public:
> C(int y_) : y(y_), A(y_) { }
> long y;
> };
>
> class B {
> public:
> B() : a(1) { }
> void f2() {
> std::cout << "A:" << a.z << std::endl;
> }
> A a;
> };
> class D: public B {
> public:
> B() : a(3) { }
> void f2() {
> std::cout << "A:" << a.z << std::endl;
> }
> C a;
> };
>
> ---------------------------------------
>
> Aqui donde aparecen los problemas, si creas B puedes acceder a los datos
> de A con las funciones de B. Pero si creas D, accedes a los datos de C+A
> con las funciones de D y C, pero tan pronto llamas a las funciones
> heredadas de B, B solo puede acceder a los datos de A que estan totalmente
> en desuso, es decir, crear una instancia en D genera en la memoria una
> variable "a" con C+A, y tambien una variable "a" con A, siendo en la clase
> D un C+A,A , donde la ultima A no se usa, solo C+A , en A se termina usando
> cuando se llama a las funciones de B.
> Solo es posible crear una nueva funcion tipo virtual como unico caso
> para acceder solamente a C+A, pero esto genera codigo basura y en la
> memoria se reserva A como basura:
>
> Code:
> ---------------------------------------
> #include <iostream>
>
> class A {
> public:
> A(int z_) : z(z_) { }
> int z;
> };
>
> class C: public A {
> public:
> C(int z_) : A(z_) { }
> };
>
> class B {
> public:
> B() : a(1) { }
> void f2() {
> std::cout << "A:" << get_C_a().z << std::endl;
> }
> virtual A const& get_C_a() { return a; }
> A a; // Use only from B
> };
>
> class D : public B {
> public:
> D() : a(3) { }
> void f2(){
> std::cout << "C+A:" << a.z << std::endl;
> B::f2();
> }
> C a; // Use C+A only from D
> A const& get_C_a() override { return a; }
> };
>
> int main() {
> B b; D d;
> b.f2(); d.f2();
> return 0;
> }
>
> /* OUTPUT:
> A:1
> C+A:3
> A:3
> */
>
> ---------------------------------------
>
> Esta seria la mejor opcion, pero no la ideal. Lo ideal es que "C a;" de D
> remplace a "A a;" de B, de esta forma D solo usa C+A de "C a;" y B solo usa
> A de "A a;"
>
> Esta es mi propuesta, una palabra clave como 'virtual' (o puede ser
> cualquier otra) en la variable del mismo nombre que se remplace a la
> definicion de variable de la clase base.
>
> Por ejemplo:
> Code:
> ---------------------------------------
> #include <iostream>
>
> class A {
> public:
> A(int z_) : z(z_) { }
> int z;
> };
>
> class C: public A {
> public:
> C(int z_) : A(z_) { }
> };
>
> class B {
> public:
> B() : a(1) { }
> void f2() {
> std::cout << "A:" << a.z << std::endl;
> }
> virtual A a; // Use A only from B
> };
>
> class D : public B {
> public:
> D() : a(3) { }
> void f2(){
> std::cout << "C+A:" << a.z << std::endl;
> B::f2();
> }
> virtual C a; // Use C+A only from D
> };
>
>
>
[snip]
This problem sounds similar to the "dual inheritance
hierarchy" problem that this reference:
https://pdfs.semanticscholar.org/f403/361d9ef3dac96463787b852b605a918bc4fe.pdf
addresses. For example, the A and B classes above
correspond to the B1 and B2 classes in Figure 3 of the above
reference, and the C and D classes above correspond to the
D1 and D2 classes in Figure 3 of the above reference.
Is that how it seems to you?
-regards,
Larry
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/ebc202be-4def-427a-95ff-7239efb4b89f%40isocpp.org.
------=_Part_11542_1573015084.1531908273240
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>On Monday, June 11, 2018 at 7:17:54 PM UTC-5, rmb.=
...@gmail.com wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;mar=
gin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D=
"ltr">We have 2 classes that contain different data sets, one needs to use =
the functions and variables of another class, so it is included as a member=
pointing to the other class:<br><br>=C2=A0=C2=A0 member<br>A -------> B=
<br><br>Code:<br>------------------------------<wbr>---------<br><br>class =
A {<br>public:<br>=C2=A0=C2=A0 =C2=A0A(int z_) : z(z_) {=C2=A0=C2=A0 =C2=A0=
}<br>=C2=A0=C2=A0 =C2=A0int z;<br>};<br><br>class B {<br>public:<br>=C2=A0=
=C2=A0 =C2=A0B() : a(1) { }<br>=C2=A0=C2=A0 =C2=A0void f2() {<br>=C2=A0=C2=
=A0 =C2=A0=C2=A0=C2=A0 =C2=A0std::cout << "A:" << a.z=
<< std::endl;<br>=C2=A0=C2=A0 =C2=A0}<br>=C2=A0=C2=A0 =C2=A0A a;<br>=
};<br><br>------------------------------<wbr>---------<br><br>Then you need=
to create an inheritance for each class, since you need to cover a new int=
erface layer. Let's call C and D, where C uses the base class A and D u=
ses the base class B.<br><br>=C2=A0=C2=A0 member<br>A ---------> 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>------------------------------<wbr>---------<br><br=
>class A {<br>public:<br>=C2=A0=C2=A0 =C2=A0A(int z_) : z(z_) {=C2=A0=C2=A0=
=C2=A0}<br>=C2=A0=C2=A0 =C2=A0int z;<br>};<br>class C: public A {<br>publi=
c:<br>=C2=A0=C2=A0 =C2=A0C(int y_) : y(y_), A(y_) {=C2=A0=C2=A0 =C2=A0}<br>=
=C2=A0=C2=A0 =C2=A0long y;<br>};<br><br>class B {<br>public:<br>=C2=A0=C2=
=A0 =C2=A0B() : a(1) { }<br>=C2=A0=C2=A0 =C2=A0void f2() {<br>=C2=A0=C2=A0 =
=C2=A0=C2=A0=C2=A0 =C2=A0std::cout << "A:" << a.z <=
;< std::endl;<br>=C2=A0=C2=A0 =C2=A0}<br>=C2=A0=C2=A0 =C2=A0A a;<br>};<b=
r>class D: public B {<br>public:<br>=C2=A0=C2=A0 =C2=A0B() : a(3) { }<br>=
=C2=A0=C2=A0 =C2=A0void f2() {<br>=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0std=
::cout << "A:" << a.z << 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 "a" with C+A, and also a variable "a"=
with A , being in class D a C+A, A, where the last A is not used, only C+A=
, in A it ends up using when the functions of B. are called.<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 <iostream><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 << "A:" << get_C_a().=
z << std::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 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 << "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 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, "C a;" =
of D replace "A a;" of B, in this way D only uses C+A from "=
C a;" and B only uses A from "A a;"<br><br>This is my propos=
al, a keyword like 'virtual' (or can be any other) in the variable =
of the same name that is replaced by the variable definition of the base cl=
ass.<br><br>Por ejemplo:<br>Code:<br>------------------------------<wbr>---=
------<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=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 << "A:" <&l=
t; a.z << 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 << "C+A:" &=
lt;< 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<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 -------> 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 << "A:" << a.z << 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 ---------> 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>--------------------=
----------<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 << =
"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>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 << "A:" << a.z=
<< 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 "a"=
con C+A, y tambien una variable "a" con A, siendo en la clase D =
un C+A,A , donde la ultima A no se usa, solo C+A , en A se termina usando 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 <iostream><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 << "A:" << get_C_a().z &=
lt;< std::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 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 << "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.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 "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, una=
palabra clave como 'virtual' (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 <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>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 << "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 {<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 << "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><br></div></blockquote><div><br></div><d=
iv>[snip]</div><div> This problem sounds similar to the "dual inherita=
nce<br>hierarchy" problem that this reference:<br><br>https://pdfs.sem=
anticscholar.org/f403/361d9ef3dac96463787b852b605a918bc4fe.pdf<br><br>addre=
sses.=C2=A0 For example, the A and B classes above<br>correspond to the B1 =
and B2 classes in Figure 3 of the above<br>reference, and the C and D class=
es above correspond to the<br>D1 and D2 classes in Figure 3 of the above re=
ference.<br><br>Is that how it seems to you?<br><br>-regards,<br>Larry<br><=
br></div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/ebc202be-4def-427a-95ff-7239efb4b89f%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/ebc202be-4def-427a-95ff-7239efb4b89f=
%40isocpp.org</a>.<br />
------=_Part_11542_1573015084.1531908273240--
------=_Part_11541_1987043502.1531908273240--
.
Author: rmbeer2@gmail.com
Date: Wed, 25 Jul 2018 10:16:43 -0700 (PDT)
Raw View
------=_Part_9518_1313330686.1532539003444
Content-Type: multipart/alternative;
boundary="----=_Part_9519_957408359.1532539003445"
------=_Part_9519_957408359.1532539003445
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Yes, that's exactly what I was looking for!
I did not know that the keyword 'mutable' had to be used, although there is=
=20
still the problem of having to use the virtual function to directly extract=
=20
the class already converted from a parent class...
The class structure that I use is similar, but directly uses a "D2 itsD2;",=
=20
a direct statement within the class itself...
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D
si, es justamente lo que estaba buscando!...
no sabia que habia que usar la palabra clave 'mutable', aunque sigue=20
estando el problema de tener que usar la funcion virtual para extraer=20
directamente la clase ya convertida desde una clase padre...
La estructura de clases que yo uso es similar, pero usa directamente un "D2=
=20
itsD2;", una declaraci=C3=B3n directa dentro de la propia clase...
El mi=C3=A9rcoles, 18 de julio de 2018, 7:04:33 (UTC-3), cpplj...@gmail.com=
=20
escribi=C3=B3:
>
>
>
> On Monday, June 11, 2018 at 7:17:54 PM UTC-5, rmb...@gmail.com wrote:
>>
>> We have 2 classes that contain different data sets, one needs to use the=
=20
>> functions and variables of another class, so it is included as a member=
=20
>> pointing to the other class:
>>
>> member
>> A -------> B
>>
>> Code:
>> ---------------------------------------
>>
>> class A {
>> public:
>> A(int z_) : z(z_) { }
>> int z;
>> };
>>
>> class B {
>> public:
>> B() : a(1) { }
>> void f2() {
>> std::cout << "A:" << a.z << std::endl;
>> }
>> A a;
>> };
>>
>> ---------------------------------------
>>
>> Then you need to create an inheritance for each class, since you need to=
=20
>> cover a new interface layer. Let's call C and D, where C uses the base=
=20
>> class A and D uses the base class B.
>>
>> member
>> A ---------> B
>> | |
>> |inheritance | inheritance
>> | |
>> v member v
>> C ---------> D
>>
>> Code:
>> ---------------------------------------
>>
>> class A {
>> public:
>> A(int z_) : z(z_) { }
>> int z;
>> };
>> class C: public A {
>> public:
>> C(int y_) : y(y_), A(y_) { }
>> long y;
>> };
>>
>> class B {
>> public:
>> B() : a(1) { }
>> void f2() {
>> std::cout << "A:" << a.z << std::endl;
>> }
>> A a;
>> };
>> class D: public B {
>> public:
>> B() : a(3) { }
>> void f2() {
>> std::cout << "A:" << a.z << std::endl;
>> }
>> C a;
>> };
>>
>> ---------------------------------------
>>
>> Here where the problems appear, if you create B you can access the data=
=20
>> of A with the functions of B. But if you create D, you access the data o=
f=20
>> C+A with the functions of D and C, but as soon as you call the functions=
=20
>> inherited from B, B can only access the data of A that are totally in=20
>> disuse, that is, create an instance in D generates in memory a variable =
"a"=20
>> with C+A, and also a variable "a" with A , being in class D a C+A, A, wh=
ere=20
>> the last A is not used, only C+A, in A it ends up using when the functio=
ns=20
>> of B. are called.
>> It is only possible to create a new virtual type function as the only=
=20
>> case to access only C+A, but this generates junk code and in memory it=
=20
>> reserves A as garbage:
>>
>> Code:
>> ---------------------------------------
>> #include <iostream>
>>
>> class A {
>> public:
>> A(int z_) : z(z_) { }
>> int z;
>> };
>>
>> class C: public A {
>> public:
>> C(int z_) : A(z_) { }
>> };
>>
>> class B {
>> public:
>> B() : a(1) { }
>> void f2() {
>> std::cout << "A:" << get_C_a().z << std::endl;
>> }
>> virtual A const& get_C_a() { return a; }
>> A a; // Use only from B
>> };
>>
>> class D : public B {
>> public:
>> D() : a(3) { }
>> void f2(){
>> std::cout << "C+A:" << a.z << std::endl;
>> B::f2();
>> }
>> C a; // Use C+A only from D
>> A const& get_C_a() override { return a; }
>> };
>>
>> int main() {
>> B b; D d;
>> b.f2(); d.f2();
>> return 0;
>> }
>>
>> /* OUTPUT:
>> A:1
>> C+A:3
>> A:3
>> */
>>
>> ---------------------------------------
>>
>> This would be the best option, but not the ideal one. Ideally, "C a;" of=
=20
>> D replace "A a;" of B, in this way D only uses C+A from "C a;" and B onl=
y=20
>> uses A from "A a;"
>>
>> This is my proposal, a keyword like 'virtual' (or can be any other) in=
=20
>> the variable of the same name that is replaced by the variable definitio=
n=20
>> of the base class.
>>
>> Por ejemplo:
>> Code:
>> ---------------------------------------
>> #include <iostream>
>>
>> class A {
>> public:
>> A(int z_) : z(z_) { }
>> int z;
>> };
>>
>> class C: public A {
>> public:
>> C(int z_) : A(z_) { }
>> };
>>
>> class B {
>> public:
>> B() : a(1) { }
>> void f2() {
>> std::cout << "A:" << a.z << std::endl;
>> }
>> virtual A a; // Use A only from B
>> };
>>
>> class D : public B {
>> public:
>> D() : a(3) { }
>> void f2(){
>> std::cout << "C+A:" << a.z << std::endl;
>> B::f2();
>> }
>> virtual C a; // Use C+A only from D
>> };
>>
>> int main() {
>> B b; D d;
>> b.f2(); d.f2();
>> return 0;
>> }
>>
>> /* OUTPUT:
>> A:1
>> C+A:3
>> A:3
>> */
>>
>> ---------------------------------------
>>
>> well this might not be possible, since compiled the code, the binary cod=
e=20
>> uses the data from an expected position in the variables within the=20
>> classes, so removing it from the list could alter the size and position =
of=20
>> the variables. On the other hand it would be possible, since reserving=
=20
>> memory from A or from C as C+A, generates a group of variables reserved =
in=20
>> memories for each class even if it is C+A and calls functions of A which=
=20
>> omits C of C+A Just to have A in view, this could be an advantage.
>> I suggest some other option to simulate a replacement of variable A by C=
..
>> If there is a better method that fulfills the same purpose without=20
>> breaking with the basic structure proposed here then much better.
>>
>>
>> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D
>>
>> Tenemos 2 clases que contienen distintos conjuntos de datos, uno necesit=
a=20
>> usar las funciones y variables de otra clase, por lo que se incluye como=
=20
>> miembro apuntando a la otra clase:
>>
>> member
>> A -------> B
>>
>> Code:
>> ---------------------------------------
>>
>> class A {
>> public:
>> A(int z_) : z(z_) { }
>> int z;
>> };
>>
>> class B {
>> public:
>> B() : a(1) { }
>> void f2() {
>> std::cout << "A:" << a.z << std::endl;
>> }
>> A a;
>> };
>>
>> ---------------------------------------
>>
>> Luego se necesita crear una herencia para cada clase, ya que necesita=20
>> cubrir una nueva capa de interfaz. Llamemos C y D, donde C usa la clase=
=20
>> base A y D usa la clase base B.
>>
>> member
>> A ---------> B
>> | |
>> |inheritance | inheritance
>> | |
>> v member v
>> C ---------> D
>>
>> Code:
>> ---------------------------------------
>>
>> class A {
>> public:
>> A(int z_) : z(z_) { }
>> int z;
>> };
>> class C: public A {
>> public:
>> C(int y_) : y(y_), A(y_) { }
>> long y;
>> };
>>
>> class B {
>> public:
>> B() : a(1) { }
>> void f2() {
>> std::cout << "A:" << a.z << std::endl;
>> }
>> A a;
>> };
>> class D: public B {
>> public:
>> B() : a(3) { }
>> void f2() {
>> std::cout << "A:" << a.z << std::endl;
>> }
>> C a;
>> };
>>
>> ---------------------------------------
>>
>> Aqui donde aparecen los problemas, si creas B puedes acceder a los=20
>> datos de A con las funciones de B. Pero si creas D, accedes a los datos =
de=20
>> C+A con las funciones de D y C, pero tan pronto llamas a las funciones=
=20
>> heredadas de B, B solo puede acceder a los datos de A que estan totalmen=
te=20
>> en desuso, es decir, crear una instancia en D genera en la memoria una=
=20
>> variable "a" con C+A, y tambien una variable "a" con A, siendo en la cla=
se=20
>> D un C+A,A , donde la ultima A no se usa, solo C+A , en A se termina usa=
ndo=20
>> cuando se llama a las funciones de B.
>> Solo es posible crear una nueva funcion tipo virtual como unico caso=
=20
>> para acceder solamente a C+A, pero esto genera codigo basura y en la=20
>> memoria se reserva A como basura:
>>
>> Code:
>> ---------------------------------------
>> #include <iostream>
>>
>> class A {
>> public:
>> A(int z_) : z(z_) { }
>> int z;
>> };
>>
>> class C: public A {
>> public:
>> C(int z_) : A(z_) { }
>> };
>>
>> class B {
>> public:
>> B() : a(1) { }
>> void f2() {
>> std::cout << "A:" << get_C_a().z << std::endl;
>> }
>> virtual A const& get_C_a() { return a; }
>> A a; // Use only from B
>> };
>>
>> class D : public B {
>> public:
>> D() : a(3) { }
>> void f2(){
>> std::cout << "C+A:" << a.z << std::endl;
>> B::f2();
>> }
>> C a; // Use C+A only from D
>> A const& get_C_a() override { return a; }
>> };
>>
>> int main() {
>> B b; D d;
>> b.f2(); d.f2();
>> return 0;
>> }
>>
>> /* OUTPUT:
>> A:1
>> C+A:3
>> A:3
>> */
>>
>> ---------------------------------------
>>
>> Esta seria la mejor opcion, pero no la ideal. Lo ideal es que "C a;" de =
D=20
>> remplace a "A a;" de B, de esta forma D solo usa C+A de "C a;" y B solo =
usa=20
>> A de "A a;"
>>
>> Esta es mi propuesta, una palabra clave como 'virtual' (o puede ser=20
>> cualquier otra) en la variable del mismo nombre que se remplace a la=20
>> definicion de variable de la clase base.
>>
>> Por ejemplo:
>> Code:
>> ---------------------------------------
>> #include <iostream>
>>
>> class A {
>> public:
>> A(int z_) : z(z_) { }
>> int z;
>> };
>>
>> class C: public A {
>> public:
>> C(int z_) : A(z_) { }
>> };
>>
>> class B {
>> public:
>> B() : a(1) { }
>> void f2() {
>> std::cout << "A:" << a.z << std::endl;
>> }
>> virtual A a; // Use A only from B
>> };
>>
>> class D : public B {
>> public:
>> D() : a(3) { }
>> void f2(){
>> std::cout << "C+A:" << a.z << std::endl;
>> B::f2();
>> }
>> virtual C a; // Use C+A only from D
>> };
>>
>>
>>
> [snip]
> This problem sounds similar to the "dual inheritance
> hierarchy" problem that this reference:
>
>
> https://pdfs.semanticscholar.org/f403/361d9ef3dac96463787b852b605a918bc4f=
e.pdf
>
> addresses. For example, the A and B classes above
> correspond to the B1 and B2 classes in Figure 3 of the above
> reference, and the C and D classes above correspond to the
> D1 and D2 classes in Figure 3 of the above reference.
>
> Is that how it seems to you?
>
> -regards,
> Larry
>
>
--=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/3a9e87f5-de59-4297-8096-f8f887b9f656%40isocpp.or=
g.
------=_Part_9519_957408359.1532539003445
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Yes, that's exactly what I was looking for!<br>I did n=
ot know that the keyword 'mutable' 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 "D2 itsD2;", a direc=
t statement within the class itself...<br><br>=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D<br><br>si, =
es justamente lo que estaba buscando!...<br>no sabia que habia que usar la =
palabra clave 'mutable', aunque sigue estando el problema de tener =
que usar la funcion virtual para extraer directamente la clase ya convertid=
a desde una clase padre...<br>La estructura de clases que yo uso es similar=
, pero usa directamente un "D2 itsD2;", una declaraci=C3=B3n dire=
cta dentro de la propia clase...<br><br>El mi=C3=A9rcoles, 18 de julio de 2=
018, 7:04:33 (UTC-3), cpplj...@gmail.com escribi=C3=B3:<blockquote class=3D=
"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc s=
olid;padding-left: 1ex;"><div dir=3D"ltr"><br><br>On Monday, June 11, 2018 =
at 7:17:54 PM UTC-5, <a>rmb...@gmail.com</a> wrote:<blockquote class=3D"gma=
il_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;pa=
dding-left:1ex"><div dir=3D"ltr">We have 2 classes that contain different d=
ata sets, one needs to use the functions and variables of another class, so=
it is included as a member pointing to the other class:<br><br>=C2=A0=C2=
=A0 member<br>A -------> B<br><br>Code:<br>-----------------------------=
-<wbr>---------<br><br>class A {<br>public:<br>=C2=A0=C2=A0 =C2=A0A(int z_)=
: z(z_) {=C2=A0=C2=A0 =C2=A0}<br>=C2=A0=C2=A0 =C2=A0int z;<br>};<br><br>cl=
ass B {<br>public:<br>=C2=A0=C2=A0 =C2=A0B() : a(1) { }<br>=C2=A0=C2=A0 =C2=
=A0void f2() {<br>=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0std::cout << =
"A:" << a.z << std::endl;<br>=C2=A0=C2=A0 =C2=A0}<br>=
=C2=A0=C2=A0 =C2=A0A a;<br>};<br><br>------------------------------<wbr>---=
------<br><br>Then you need to create an inheritance for each class, since =
you need to cover a new interface layer. Let's call C and D, where C us=
es the base class A and D uses the base class B.<br><br>=C2=A0=C2=A0 member=
<br>A ---------> 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>-----------------------=
-------<wbr>---------<br><br>class A {<br>public:<br>=C2=A0=C2=A0 =C2=A0A(i=
nt z_) : z(z_) {=C2=A0=C2=A0 =C2=A0}<br>=C2=A0=C2=A0 =C2=A0int z;<br>};<br>=
class C: public A {<br>public:<br>=C2=A0=C2=A0 =C2=A0C(int y_) : y(y_), A(y=
_) {=C2=A0=C2=A0 =C2=A0}<br>=C2=A0=C2=A0 =C2=A0long y;<br>};<br><br>class B=
{<br>public:<br>=C2=A0=C2=A0 =C2=A0B() : a(1) { }<br>=C2=A0=C2=A0 =C2=A0vo=
id f2() {<br>=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0std::cout << "=
;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>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 << "A:" << a.z <=
;< std::endl;<br>=C2=A0=C2=A0 =C2=A0}<br>=C2=A0=C2=A0 =C2=A0C a;<br>};<b=
r><br>------------------------------<wbr>---------<br><br>Here where the pr=
oblems appear, if you create B you can access the data of A with the functi=
ons of B. But if you create D, you access the data of C+A with the function=
s of D and C, but as soon as you call the functions inherited from B, B can=
only access the data of A that are totally in disuse, that is, create an i=
nstance in D generates in memory a variable "a" with C+A, and als=
o a variable "a" with A , being in class D a C+A, A, where the la=
st A is not used, only C+A, in A it ends up using when the functions of B. =
are called.<br>=C2=A0 It is only possible to create a new virtual type func=
tion as the only case to access only C+A, but this generates junk code and =
in memory it reserves A as garbage:<br><br>Code:<br>-----------------------=
-------<wbr>---------<br>#include <iostream><br><br>class A {<br>publ=
ic:<br>=C2=A0=C2=A0 =C2=A0A(int z_) : z(z_) {=C2=A0=C2=A0 =C2=A0}<br>=C2=A0=
=C2=A0 =C2=A0int z;<br>};<br><br>class C: public A {<br>public:<br>=C2=A0=
=C2=A0 =C2=A0C(int z_) : A(z_) {=C2=A0=C2=A0 =C2=A0}<br>};<br><br>class B {=
<br>public:<br>=C2=A0=C2=A0 =C2=A0B() : a(1) { }<br>=C2=A0=C2=A0 =C2=A0void=
f2() {<br>=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0std::cout << "A=
:" << get_C_a().z << std::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>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=A0C a; // Use C+A o=
nly 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.f2();<br>=C2=A0=C2=A0 =C2=A0return 0;<br>}<br><br>/* OU=
TPUT:<br>A:1<br>C+A:3<br>A:3<br>*/<br><br>------------------------------<wb=
r>---------<br><br>This would be the best option, but not the ideal one. Id=
eally, "C a;" of D replace "A a;" of B, in this way D o=
nly uses C+A from "C a;" and B only 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 that is replaced by the variable d=
efinition of the base class.<br><br>Por ejemplo:<br>Code:<br>--------------=
----------------<wbr>---------<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>cl=
ass B {<br>public:<br>=C2=A0=C2=A0 =C2=A0B() : a(1) { }<br>=C2=A0=C2=A0 =C2=
=A0void f2() {<br>=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0std::cout << =
"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 <&l=
t; "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=A0v=
irtual C a; // Use C+A only from D<br>};<br><br>int main() {<br>=C2=A0=C2=
=A0 =C2=A0B b; D d;<br>=C2=A0=C2=A0 =C2=A0b.f2(); d.f2();<br>=C2=A0=C2=A0 =
=C2=A0return 0;<br>}<br><br>/* OUTPUT:<br>A:1<br>C+A:3<br>A:3<br>*/<br><br>=
------------------------------<wbr>---------<br><br>well this might not be =
possible, since compiled the code, the binary code uses the data from an ex=
pected position in the variables within the classes, so removing it from th=
e list could alter the size and position of the variables. On the other han=
d it would be possible, since reserving memory from A or from C as C+A, gen=
erates a group of variables reserved in memories for each class even if it =
is C+A and calls functions of A which omits C of C+A Just to have A in view=
, this could be an advantage.<br>I suggest some other option to simulate a =
replacement of variable A by C.<br>If there is a better method that fulfill=
s the same purpose without breaking with the basic structure proposed here =
then much better.<br><br>=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D<wbr>=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D<wbr>=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D<br><br>Tenemos 2 cla=
ses que contienen distintos conjuntos de datos, uno necesita usar las funci=
ones y variables de otra clase, por lo que se incluye como miembro apuntand=
o a la otra clase:<br><br>=C2=A0=C2=A0 member<br>A -------> B<br><br>Cod=
e:<br>------------------------------<wbr>---------<br><br>class A {<br>publ=
ic:<br>=C2=A0=C2=A0 =C2=A0A(int z_) : z(z_) {=C2=A0=C2=A0 =C2=A0}<br>=C2=A0=
=C2=A0 =C2=A0int z;<br>};<br><br>class B {<br>public:<br>=C2=A0=C2=A0 =C2=
=A0B() : a(1) { }<br>=C2=A0=C2=A0 =C2=A0void f2() {<br>=C2=A0=C2=A0 =C2=A0=
=C2=A0=C2=A0 =C2=A0std::cout << "A:" << a.z << =
std::endl;<br>=C2=A0=C2=A0 =C2=A0}<br>=C2=A0=C2=A0 =C2=A0A a;<br>};<br><br>=
------------------------------<wbr>---------<br><br>Luego se necesita crear=
una herencia para cada clase, ya que necesita cubrir una nueva capa de int=
erfaz. Llamemos C y D, donde C usa la clase base A y D usa la clase base B.=
<br><br>=C2=A0=C2=A0 member<br>A ---------> B<br>|=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 |<br>|inheritance | inheritan=
ce<br>|=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 |=
<br>v=C2=A0 member=C2=A0=C2=A0=C2=A0 v<br>C ---------> D<br><br>Code:<br=
>------------------------------<wbr>---------<br><br>class A {<br>public:<b=
r>=C2=A0=C2=A0 =C2=A0A(int z_) : z(z_) {=C2=A0=C2=A0 =C2=A0}<br>=C2=A0=C2=
=A0 =C2=A0int z;<br>};<br>class C: public A {<br>public:<br>=C2=A0=C2=A0 =
=C2=A0C(int y_) : y(y_), A(y_) {=C2=A0=C2=A0 =C2=A0}<br>=C2=A0=C2=A0 =C2=A0=
long y;<br>};<br><br>class B {<br>public:<br>=C2=A0=C2=A0 =C2=A0B() : a(1) =
{ }<br>=C2=A0=C2=A0 =C2=A0void f2() {<br>=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =
=C2=A0std::cout << "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>public:<br>=C2=A0=C2=A0 =C2=A0B() : a(3) { }<br>=C2=A0=C2=A0 =C2=A0vo=
id f2() {<br>=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0std::cout << "=
;A:" << a.z << std::endl;<br>=C2=A0=C2=A0 =C2=A0}<br>=C2=
=A0=C2=A0 =C2=A0C a;<br>};<br><br>------------------------------<wbr>------=
---<br><br>=C2=A0 Aqui donde aparecen los problemas, si creas B puedes acce=
der a los datos de A con las funciones de B. Pero si creas D, accedes a los=
datos de C+A con las funciones de D y C, pero tan pronto llamas a las func=
iones heredadas de B, B solo puede acceder a los datos de A que estan total=
mente en desuso, es decir, crear una instancia en D genera en la memoria un=
a variable "a" con C+A, y tambien una variable "a" con =
A, siendo en la clase D un C+A,A , donde la ultima A no se usa, solo C+A , =
en A se termina usando cuando se llama a las funciones de B.<br>=C2=A0=C2=
=A0 =C2=A0Solo es posible crear una nueva funcion tipo virtual como unico c=
aso para acceder solamente a C+A, pero esto genera codigo basura y en la me=
moria se reserva A como basura:<br><br>Code:<br>---------------------------=
---<wbr>---------<br>#include <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:&q=
uot; << get_C_a().z << std::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>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=A0C a; // Use C+A o=
nly 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.f2();<br>=C2=A0=C2=A0 =C2=A0return 0;<br>}<br><br>/* OU=
TPUT:<br>A:1<br>C+A:3<br>A:3<br>*/<br><br>------------------------------<wb=
r>---------<br><br>Esta seria la mejor opcion, pero no la ideal. Lo ideal e=
s que "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, una palabra clave como 'virtual' (o puede =
ser cualquier otra) en la variable del mismo nombre que se remplace a la de=
finicion de variable de la clase base.<br><br>Por ejemplo:<br>Code:<br>----=
--------------------------<wbr>---------<br>#include <iostream><br><b=
r>class A {<br>public:<br>=C2=A0=C2=A0 =C2=A0A(int z_) : z(z_) {=C2=A0=C2=
=A0 =C2=A0}<br>=C2=A0=C2=A0 =C2=A0int z;<br>};<br><br>class C: public A {<b=
r>public:<br>=C2=A0=C2=A0 =C2=A0C(int z_) : A(z_) {=C2=A0=C2=A0 =C2=A0}<br>=
};<br><br>class B {<br>public:<br>=C2=A0=C2=A0 =C2=A0B() : a(1) { }<br>=C2=
=A0=C2=A0 =C2=A0void f2() {<br>=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0std::c=
out << "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>};<b=
r><br>class D : public B {<br>public:<br>=C2=A0=C2=A0 =C2=A0D() : a(3) { }<=
br>=C2=A0=C2=A0 =C2=A0void f2(){<br>=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0s=
td::cout << "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><br></div>=
</blockquote><div><br></div><div>[snip]</div><div> This problem sounds simi=
lar to the "dual inheritance<br>hierarchy" problem that this refe=
rence:<br><br><a href=3D"https://pdfs.semanticscholar.org/f403/361d9ef3dac9=
6463787b852b605a918bc4fe.pdf" target=3D"_blank" rel=3D"nofollow" onmousedow=
n=3D"this.href=3D'https://www.google.com/url?q\x3dhttps%3A%2F%2Fpdfs.se=
manticscholar.org%2Ff403%2F361d9ef3dac96463787b852b605a918bc4fe.pdf\x26sa\x=
3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEQHoEJF7O51Coju_EhQAXdD0kSNw';return t=
rue;" onclick=3D"this.href=3D'https://www.google.com/url?q\x3dhttps%3A%=
2F%2Fpdfs.semanticscholar.org%2Ff403%2F361d9ef3dac96463787b852b605a918bc4fe=
..pdf\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEQHoEJF7O51Coju_EhQAXdD0kSNw&#=
39;;return true;">https://pdfs.semanticscholar.<wbr>org/f403/<wbr>361d9ef3d=
ac96463787b852b605a91<wbr>8bc4fe.pdf</a><br><br>addresses.=C2=A0 For exampl=
e, the A and B classes above<br>correspond to the B1 and B2 classes in Figu=
re 3 of the above<br>reference, and the C and D classes above correspond to=
the<br>D1 and D2 classes in Figure 3 of the above reference.<br><br>Is tha=
t how it seems to you?<br><br>-regards,<br>Larry<br><br></div></div></block=
quote></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/3a9e87f5-de59-4297-8096-f8f887b9f656%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/3a9e87f5-de59-4297-8096-f8f887b9f656=
%40isocpp.org</a>.<br />
------=_Part_9519_957408359.1532539003445--
------=_Part_9518_1313330686.1532539003444--
.
Author: rmbeer2@gmail.com
Date: Sat, 11 Aug 2018 08:50:01 -0700 (PDT)
Raw View
------=_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& 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& d2=
) : itsD2(d2) {};<br>=C2=A0 virtual D2& GetB2() const {return itsD2;}<b=
r>private:<br>=C2=A0 mutable D2& 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 "itsD2=
.." por "GetB2().", 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&d2=
=3D*((D2)itsD2);<br>d2.var;<br>d2.var;<br>d2.var;<br><br>Es decir, hacer un=
a referencia de un "void*itsD2;" desde B1 en lugar de un "mu=
table D2&itsD2;" en D1....<br><br>la finalidad de esta propuesta e=
s utilizar "d2.var" en lugar de "GetB2().var", 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's exactly what I was looking for!<br>I did n=
ot know that the keyword 'mutable' 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 "D2 itsD2;", 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 'mutable', 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 "D2 itsD2;", 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 -------> 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 << "A:" << a.z << 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'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 ---------> 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>-------=
-----------------------<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 << "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>------------------------------<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 "a"=
with C+A, and also a variable "a" with A , being in class D a C+=
A, A, where the last A is not used, only C+A, in A it ends up using when 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 <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>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=
<< "A:" << get_C_a().z << std::endl;<br>=C2=A0=
=C2=A0 =C2=A0}<br>=C2=A0=C2=A0 =C2=A0virtual A const& 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 <&l=
t; "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() 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, "C a;" of D replace "A a;" of B, =
in this way D only uses C+A from "C a;" and B only uses A from &q=
uot;A a;"<br><br>This is my proposal, a keyword like 'virtual'=
(or can be any other) in the variable of the same name that is replaced by=
the variable definition of the base class.<br><br>Por ejemplo:<br>Code:<br=
>------------------------------<wbr>---------<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:" << 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 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 ------->=
; 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 << "A:" << =
a.z << 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 ---------> 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<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 << "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>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;< "A:" << a.z << 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 "a" con C+A, y tambien una variable "a=
" con A, siendo en la clase D un C+A,A , donde la ultima A no se usa, =
solo C+A , en A se termina usando cuando se llama a las funciones de B.<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 <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>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 << =
"A:" << get_C_a().z << std::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=A0voi=
d 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; // Us=
e C+A only from D<br>=C2=A0=C2=A0 =C2=A0A const& 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 "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, una palabra clave como 'virtual' (o =
puede ser cualquier otra) en la variable del mismo nombre que se remplace a=
la definicion de variable de la clase base.<br><br>Por ejemplo:<br>Code:<b=
r>------------------------------<wbr>---------<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:" << 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::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 "dual inheritance<br>hierarchy" 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'https://www.google.com/url?q\x3dhttps%3A%2=
F%2Fpdfs.semanticscholar.org%2Ff403%2F361d9ef3dac96463787b852b605a918bc4fe.=
pdf\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEQHoEJF7O51Coju_EhQAXdD0kSNw=
9;;return true;" onclick=3D"this.href=3D'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';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" 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--
.
Author: rmbeer2@gmail.com
Date: Sat, 11 Aug 2018 10:18:43 -0700 (PDT)
Raw View
------=_Part_1122_1690269230.1534007923479
Content-Type: multipart/alternative;
boundary="----=_Part_1123_44270953.1534007923479"
------=_Part_1123_44270953.1534007923479
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Use this code for compiling and test, you must find a better way!!!.....
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=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
*/
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/dc8597df-8dc3-491c-856e-280c2c6aaac7%40isocpp.or=
g.
------=_Part_1123_44270953.1534007923479
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div>Use this code for compiling and test, you must find a=
better way!!!.....<br></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<br></div><div>=
<br></div><div>#include <stdio.h></div><br>class A {<br>public:<br>=
=C2=A0 A(int z_) : z(z_) {=C2=A0=C2=A0=C2=A0 }<br>=C2=A0 virtual void f1(){=
printf("-> A (z): %d\n",z);}<br>=C2=A0 int z;<br>};<br>class C=
: public A {<br>public:<br>=C2=A0 C(int y_) : y(y_), A(y_) {=C2=A0=C2=A0=C2=
=A0 }<br>=C2=A0 virtual void f1(){printf("-> C (z): %d\n",z);A=
::f1();}<br>=C2=A0 long y;<br>};<br><br>class B {<br>public:<br>=C2=A0 B() =
{ }<br>=C2=A0 virtual int init(){<br>=C2=A0=C2=A0=C2=A0 ptra=3Dnew A(1);<br=
>=C2=A0=C2=A0=C2=A0 if(!ptra)return -1;return 0;<br>=C2=A0 }<br>=C2=A0 virt=
ual void f2() {<br>=C2=A0=C2=A0=C2=A0 A&a=3D*((A*)ptra);<br>=C2=A0=C2=
=A0=C2=A0 printf("B (a.z): %d\n",a.z);<br>=C2=A0=C2=A0=C2=A0 a.f1=
();<br>=C2=A0 }<br>=C2=A0 void*ptra;<br>};<br>class D: public B {<br>public=
:<br>=C2=A0 D() { }<br>=C2=A0 virtual int init(){<br>=C2=A0=C2=A0=C2=A0 ptr=
a=3Dnew C(3);<br>=C2=A0=C2=A0=C2=A0 if(!ptra)return -1;return 0;<br>=C2=A0 =
}<br>=C2=A0 virtual void f2() {<br>=C2=A0=C2=A0=C2=A0 C&a=3D*((C*)ptra)=
;<br>=C2=A0=C2=A0=C2=A0 printf("D (a.z): %d\n",a.z);<br>=C2=A0=C2=
=A0=C2=A0 a.f1();<br>=C2=A0=C2=A0=C2=A0 B::f2();<br>=C2=A0 }<br>};<br><br>i=
nt main(){<br>=C2=A0 D d;B b;<br><br>=C2=A0 if(d.init())return -1;<br>=C2=
=A0 if(b.init())return -1;<br>=C2=A0 <br>=C2=A0 b.f2();<br>=C2=A0 printf(&q=
uot;=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D\n");<br>=C2=A0 d.f2();<br>=C2=A0 re=
turn 0;<br>}<br><br>/* RESPUESTA:<br>B (a.z): 1<br>-> A (z): 1<br>=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D<br>D (a.z): 3<br>-> C (z): 3<br>-> A (z): 3<=
br>B (a.z): 3<br>-> C (z): 3<br>-> A (z): 3<br>*/<br><br><br>El lunes=
, 11 de junio de 2018, 21:17:54 (UTC-3), rmb...@gmail.com escribi=C3=B3:<bl=
ockquote 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 classe=
s that contain different data sets, one needs to use the functions and vari=
ables 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>-----=
-------------------------<wbr>---------<br><br>class A {<br>public:<br>=C2=
=A0=C2=A0 =C2=A0A(int z_) : z(z_) {=C2=A0=C2=A0 =C2=A0}<br>=C2=A0=C2=A0 =C2=
=A0int z;<br>};<br><br>class B {<br>public:<br>=C2=A0=C2=A0 =C2=A0B() : a(1=
) { }<br>=C2=A0=C2=A0 =C2=A0void f2() {<br>=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =
=C2=A0std::cout << "A:" << a.z << 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 inheritan=
ce for each class, since you need to cover a new interface layer. Let's=
call C and D, where C uses the base class A and D uses the base class B.<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>--=
----------------------------<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=A0=
C(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=A0st=
d::cout << "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>p=
ublic:<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:&quo=
t; << a.z << std::endl;<br>=C2=A0=C2=A0 =C2=A0}<br>=C2=A0=C2=A0=
=C2=A0C a;<br>};<br><br>------------------------------<wbr>---------<br><b=
r>Here where the problems appear, if you create B you can access the data o=
f 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 inhe=
rited from B, B can only access the data of A that are totally in disuse, t=
hat is, create an instance in D generates in memory a variable "a"=
; with C+A, and also a variable "a" with A , being in class D a C=
+A, A, where the last A is not used, only C+A, in A it ends up using when t=
he functions of B. are called.<br>=C2=A0 It is only possible to create a ne=
w virtual type function as the only case to access only C+A, but this gener=
ates junk code and in memory it reserves A as garbage:<br><br>Code:<br>----=
--------------------------<wbr>---------<br>#include <iostream><br><b=
r>class A {<br>public:<br>=C2=A0=C2=A0 =C2=A0A(int z_) : z(z_) {=C2=A0=C2=
=A0 =C2=A0}<br>=C2=A0=C2=A0 =C2=A0int z;<br>};<br><br>class C: public A {<b=
r>public:<br>=C2=A0=C2=A0 =C2=A0C(int z_) : A(z_) {=C2=A0=C2=A0 =C2=A0}<br>=
};<br><br>class B {<br>public:<br>=C2=A0=C2=A0 =C2=A0B() : a(1) { }<br>=C2=
=A0=C2=A0 =C2=A0void f2() {<br>=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0std::c=
out << "A:" << get_C_a().z << std::endl;<br>=C2=
=A0=C2=A0 =C2=A0}<br>=C2=A0=C2=A0 =C2=A0virtual A const& get_C_a() { re=
turn 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.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 no=
t the ideal one. Ideally, "C a;" of D replace "A a;" of=
B, in this way D only uses C+A from "C a;" and B only uses A fro=
m "A a;"<br><br>This is my proposal, a keyword like 'virtual&=
#39; (or can be any other) in the variable of the same name that is replace=
d by the variable definition of the base class.<br><br>Por ejemplo:<br>Code=
:<br>------------------------------<wbr>---------<br>#include <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: pub=
lic 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::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=
>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><b=
r>well this might not be possible, since compiled the code, the binary code=
uses the data from an expected position in the variables within the classe=
s, so removing it from the list could alter the size and position of the va=
riables. On the other hand it would be possible, since reserving memory fro=
m A or from C as C+A, generates a group of variables reserved in memories f=
or 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 ot=
her option to simulate a replacement of variable A by C.<br>If there is a b=
etter method that fulfills the same purpose without breaking with the basic=
structure proposed here then much better.<br><br>=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D<wbr>=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D<wbr>=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D<br><br>Tenemos 2 clases que contienen distintos conjuntos de datos, uno=
necesita usar las funciones y variables de otra clase, por lo que se inclu=
ye como miembro apuntando a la otra clase:<br><br>=C2=A0=C2=A0 member<br>A =
-------> 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>publi=
c:<br>=C2=A0=C2=A0 =C2=A0B() : a(1) { }<br>=C2=A0=C2=A0 =C2=A0void f2() {<b=
r>=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0std::cout << "A:" &=
lt;< a.z << std::endl;<br>=C2=A0=C2=A0 =C2=A0}<br>=C2=A0=C2=A0 =C2=
=A0A a;<br>};<br><br>------------------------------<wbr>---------<br><br>Lu=
ego 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 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>------------------------------<wbr>---------<br><br=
>class A {<br>public:<br>=C2=A0=C2=A0 =C2=A0A(int z_) : z(z_) {=C2=A0=C2=A0=
=C2=A0}<br>=C2=A0=C2=A0 =C2=A0int z;<br>};<br>class C: public A {<br>publi=
c:<br>=C2=A0=C2=A0 =C2=A0C(int y_) : y(y_), A(y_) {=C2=A0=C2=A0 =C2=A0}<br>=
=C2=A0=C2=A0 =C2=A0long y;<br>};<br><br>class B {<br>public:<br>=C2=A0=C2=
=A0 =C2=A0B() : a(1) { }<br>=C2=A0=C2=A0 =C2=A0void f2() {<br>=C2=A0=C2=A0 =
=C2=A0=C2=A0=C2=A0 =C2=A0std::cout << "A:" << a.z <=
;< std::endl;<br>=C2=A0=C2=A0 =C2=A0}<br>=C2=A0=C2=A0 =C2=A0A a;<br>};<b=
r>class D: public B {<br>public:<br>=C2=A0=C2=A0 =C2=A0B() : a(3) { }<br>=
=C2=A0=C2=A0 =C2=A0void f2() {<br>=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0std=
::cout << "A:" << a.z << 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, s=
i creas B puedes acceder a los datos de A con las funciones de B. Pero si c=
reas D, accedes a los datos de C+A con las funciones de D y C, pero tan pro=
nto 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 ge=
nera en la memoria una variable "a" con C+A, y tambien una variab=
le "a" con A, siendo en la clase D un C+A,A , donde la ultima A n=
o 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 v=
irtual como unico caso para acceder solamente a C+A, pero esto genera codig=
o basura y en la memoria se reserva A como basura:<br><br>Code:<br>--------=
----------------------<wbr>---------<br>#include <iostream><br><br>cl=
ass 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>pu=
blic:<br>=C2=A0=C2=A0 =C2=A0C(int z_) : A(z_) {=C2=A0=C2=A0 =C2=A0}<br>};<b=
r><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=A0virtual A const& 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 <&l=
t; "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() 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>Esta seria la mejor opcion, pero no la id=
eal. 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, una palabra clave como 'virtual=
' (o puede ser cualquier otra) en la variable del mismo nombre que se r=
emplace a la definicion de variable de la clase base.<br><br>Por ejemplo:<b=
r>Code:<br>------------------------------<wbr>---------<br>#include <ios=
tream><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>------------------------------<wbr>---------<br=
><br>bien esto podria no ser posible, ya que compilado el codigo, el codigo=
binario utiliza los datos desde una posicion esperada en las variables den=
tro 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 variabl=
es reservadas en memorias para cada clase incluso si es C+A y llamar a func=
iones 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 mejor que cumpla con el mis=
mo proposito sin romper con la estructura basica propuesta aqui entonces mu=
cho 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" 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/dc8597df-8dc3-491c-856e-280c2c6aaac7%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/dc8597df-8dc3-491c-856e-280c2c6aaac7=
%40isocpp.org</a>.<br />
------=_Part_1123_44270953.1534007923479--
------=_Part_1122_1690269230.1534007923479--
.
Author: Nicol Bolas <jmckesson@gmail.com>
Date: Sat, 11 Aug 2018 10:59:13 -0700 (PDT)
Raw View
------=_Part_1055_2378302.1534010353153
Content-Type: multipart/alternative;
boundary="----=_Part_1056_1228211383.1534010353153"
------=_Part_1056_1228211383.1534010353153
Content-Type: text/plain; charset="UTF-8"
On Saturday, August 11, 2018 at 1:18:43 PM UTC-4, rmb...@gmail.com wrote:
>
> Use this code for compiling and test, you must find a better way!!!.....
>
This is not a general forum for getting advice on how to write C++. This is
a forum for discussing proposals to change C++. So asking us to "find a
better way" is not really what this place is for.
Also, it's hard to critique or analyze code when it's so divorced from
actual use cases. If you're wanting a C++ feature to allow some thing, then
you need to show why people need to do it. Not merely that someone *could*
want it, but that people *actually do*.
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/af5214c9-a2e4-48b5-977c-bba11f244368%40isocpp.org.
------=_Part_1056_1228211383.1534010353153
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Saturday, August 11, 2018 at 1:18:43 PM UTC-4, rmb...@g=
mail.com wrote:<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=
"><div>Use this code for compiling and test, you must find a better way!!!.=
.....<br></div></div></blockquote><div><br></div><div>This is not a general =
forum for getting advice on how to write C++. This is a forum for discussin=
g proposals to change C++. So asking us to "find a better way" is=
not really what this place is for.</div><div><br></div><div>Also, it's=
hard to critique or analyze code when it's so divorced from actual use=
cases. If you're wanting a C++ feature to allow some thing, then you n=
eed to show why people need to do it. Not merely that someone <i>could</i> =
want it, but that people <i>actually do</i>.<br></div><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/af5214c9-a2e4-48b5-977c-bba11f244368%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/af5214c9-a2e4-48b5-977c-bba11f244368=
%40isocpp.org</a>.<br />
------=_Part_1056_1228211383.1534010353153--
------=_Part_1055_2378302.1534010353153--
.
Author: Jake Arkinstall <jake.arkinstall@gmail.com>
Date: Sat, 11 Aug 2018 19:51:09 +0100
Raw View
--000000000000f215af05732d5785
Content-Type: text/plain; charset="UTF-8"
What Nicol said is true - this isn't the place for help, it's a place to
discuss potential changes to the C++ language.
As bizarre and unnecessary as this approach seems (it certainly isn't
something I'd ever want to do), it's easy enough to implement just using
the code you've already been provided. D doesn't really extend B if the
type is different, but you can give B a template parameter (and supply it a
default type A). It does mean you have to provide your own conversions (and
it copies - I don't think there's any way around that). Here's an example
of that (it's a quick attempt, so it's far from perfect):
#include <utility>#include <type_traits>#include <stdio.h>
struct A{
A(const int& z)
:
z(z)
{}
virtual void f1() const{
printf("-> A (z): %d\n",z);
}
int z;
};
template<typename T=A>struct B{
B(const int& val = 1)
:
other(val)
{}
// provide a conversion between B<child of T> and B<T>
template<
typename S,
typename=std::enable_if_t<std::is_base_of_v<T, S>>
>
B(const B<S>& s):
other(static_cast<T>(s.other))
{}
virtual void f2() const{
printf("B (a.z): %d\n", other.z);
other.f1();
}
T other;
};
struct C : public A{
C(const int& val)
:
A(val),
y(val)
{}
virtual void f1() const override{
printf("-> C (z): %d\n",z);
A::f1();
}
long y;
};
struct D : public B<C>{
D(const int& val = 3)
:
B<C>(val)
{}
virtual void f2() const override{
printf("D (a.z): %d\n", other.z);
other.f1();
B::f2();
}
};
void takes_B(const B<A>& b){
b.f2();
}int main(){
D d{};
B b{};
b.f2();
printf("==========\n");
d.f2();
printf("==========\n");
takes_B(d);
return 0;
}
I've even provided a takes_B function to demonstrate how a D can be cast to
a B (implemented in the second B constructor).
Take this code, try it out (you'll need c++17, otherwise to write B<>
instead of B in the main function, replace std::enable_if_t<...> with
std::enable_if<....>::type and std::is_base_of_v<...> with
std::is_base_of<...>::value). Learn from it.
Then go away for a few years and come back when you're ready to contribute,
preferably if you've learned some manners too. I believe I speak for the
rest of us when I tell you that your attitude is absolutely unwelcome here.
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAC%2B0CCM-vHkuqH6gu7J8Gk3GJMGaOuzUQbsdEFioRsx%2B8rbEpw%40mail.gmail.com.
--000000000000f215af05732d5785
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div>What Nicol said is true - this isn't the place fo=
r help, it's a place to discuss potential changes to the C++ language.<=
br><br></div><div>As bizarre and unnecessary as this approach seems (it cer=
tainly isn't something I'd ever want to do), it's easy enough t=
o implement just using the code you've already been provided. D doesn&#=
39;t really extend B if the type is different, but you can give B a templat=
e parameter (and supply it a default type A). It does mean you have to prov=
ide your own conversions (and it copies - I don't think there's any=
way around that). Here's an example of that (it's a quick attempt,=
so it's far from perfect):<br></div><div><br></div><div><pre style=3D"=
margin:0px;line-height:125%"><span style=3D"color:rgb(188,122,0)">#include =
<utility></span>
<span style=3D"color:rgb(188,122,0)">#include <type_traits></span>
<span style=3D"color:rgb(188,122,0)">#include <stdio.h></span>
<span style=3D"color:rgb(0,128,0);font-weight:bold">struct</span> A{
A(<span style=3D"color:rgb(0,128,0);font-weight:bold">const</span> <spa=
n style=3D"color:rgb(176,0,64)">int</span><span style=3D"color:rgb(102,102,=
102)">&</span> z)
<span style=3D"color:rgb(102,102,102)">:</span>
z(z)
{}
<span style=3D"color:rgb(0,128,0);font-weight:bold">virtual</span> <spa=
n style=3D"color:rgb(176,0,64)">void</span> f1() <span style=3D"color:rgb(0=
,128,0);font-weight:bold">const</span>{
printf(<span style=3D"color:rgb(186,33,33)">"-> A (z): %d</=
span><span style=3D"color:rgb(187,102,34);font-weight:bold">\n</span><span =
style=3D"color:rgb(186,33,33)">"</span>,z);
}
<span style=3D"color:rgb(176,0,64)">int</span> z;
};
<span style=3D"color:rgb(0,128,0);font-weight:bold">template</span><span st=
yle=3D"color:rgb(102,102,102)"><</span><span style=3D"color:rgb(0,128,0)=
;font-weight:bold">typename</span> T<span style=3D"color:rgb(102,102,102)">=
=3D</span>A<span style=3D"color:rgb(102,102,102)">></span>
<span style=3D"color:rgb(0,128,0);font-weight:bold">struct</span> B{
B(<span style=3D"color:rgb(0,128,0);font-weight:bold">const</span> <spa=
n style=3D"color:rgb(176,0,64)">int</span><span style=3D"color:rgb(102,102,=
102)">&</span> val <span style=3D"color:rgb(102,102,102)">=3D</span> <s=
pan style=3D"color:rgb(102,102,102)">1</span>)
<span style=3D"color:rgb(102,102,102)">:</span>
other(val)
{}
<span style=3D"color:rgb(64,128,128);font-style:italic">// provide a co=
nversion between B<child of T> and B<T></span>
<span style=3D"color:rgb(0,128,0);font-weight:bold">template</span><spa=
n style=3D"color:rgb(102,102,102)"><</span>
<span style=3D"color:rgb(0,128,0);font-weight:bold">typename</span>=
S,
<span style=3D"color:rgb(0,128,0);font-weight:bold">typename</span>=
<span style=3D"color:rgb(102,102,102)">=3D</span>std<span style=3D"color:rg=
b(102,102,102)">::</span><span style=3D"color:rgb(176,0,64)">enable_if_t</s=
pan><span style=3D"color:rgb(102,102,102)"><</span>std<span style=3D"col=
or:rgb(102,102,102)">::</span>is_base_of_v<span style=3D"color:rgb(102,102,=
102)"><</span>T, S<span style=3D"color:rgb(102,102,102)">>></span>
<span style=3D"color:rgb(102,102,102)">></span>
B(<span style=3D"color:rgb(0,128,0);font-weight:bold">const</span> B<sp=
an style=3D"color:rgb(102,102,102)"><</span>S<span style=3D"color:rgb(10=
2,102,102)">>&</span> s)<span style=3D"color:rgb(102,102,102)">:</sp=
an>
other(<span style=3D"color:rgb(0,128,0);font-weight:bold">static_ca=
st</span><span style=3D"color:rgb(102,102,102)"><</span>T<span style=3D"=
color:rgb(102,102,102)">></span>(s.other))
{}
<span style=3D"color:rgb(0,128,0);font-weight:bold">virtual</span> <spa=
n style=3D"color:rgb(176,0,64)">void</span> f2() <span style=3D"color:rgb(0=
,128,0);font-weight:bold">const</span>{
printf(<span style=3D"color:rgb(186,33,33)">"B (a.z): %d</span=
><span style=3D"color:rgb(187,102,34);font-weight:bold">\n</span><span styl=
e=3D"color:rgb(186,33,33)">"</span>, other.z);
other.f1();
}
T other;
};
<span style=3D"color:rgb(0,128,0);font-weight:bold">struct</span> C <span s=
tyle=3D"color:rgb(102,102,102)">:</span> <span style=3D"color:rgb(0,128,0);=
font-weight:bold">public</span> A{
C(<span style=3D"color:rgb(0,128,0);font-weight:bold">const</span> <spa=
n style=3D"color:rgb(176,0,64)">int</span><span style=3D"color:rgb(102,102,=
102)">&</span> val)
<span style=3D"color:rgb(102,102,102)">:</span>
A(val),
y(val)
{}
<span style=3D"color:rgb(0,128,0);font-weight:bold">virtual</span> <spa=
n style=3D"color:rgb(176,0,64)">void</span> f1() <span style=3D"color:rgb(0=
,128,0);font-weight:bold">const</span> override{
printf(<span style=3D"color:rgb(186,33,33)">"-> C (z): %d</=
span><span style=3D"color:rgb(187,102,34);font-weight:bold">\n</span><span =
style=3D"color:rgb(186,33,33)">"</span>,z);
A<span style=3D"color:rgb(102,102,102)">::</span>f1();
}
<span style=3D"color:rgb(176,0,64)">long</span> y;
};
<span style=3D"color:rgb(0,128,0);font-weight:bold">struct</span> D <span s=
tyle=3D"color:rgb(102,102,102)">:</span> <span style=3D"color:rgb(0,128,0);=
font-weight:bold">public</span> B<span style=3D"color:rgb(102,102,102)"><=
;</span>C<span style=3D"color:rgb(102,102,102)">></span>{
D(<span style=3D"color:rgb(0,128,0);font-weight:bold">const</span> <spa=
n style=3D"color:rgb(176,0,64)">int</span><span style=3D"color:rgb(102,102,=
102)">&</span> val <span style=3D"color:rgb(102,102,102)">=3D</span> <s=
pan style=3D"color:rgb(102,102,102)">3</span>)
<span style=3D"color:rgb(102,102,102)">:</span>
B<span style=3D"color:rgb(102,102,102)"><</span>C<span style=3D"=
color:rgb(102,102,102)">></span>(val)
{}
<span style=3D"color:rgb(0,128,0);font-weight:bold">virtual</span> <spa=
n style=3D"color:rgb(176,0,64)">void</span> f2() <span style=3D"color:rgb(0=
,128,0);font-weight:bold">const</span> override{
printf(<span style=3D"color:rgb(186,33,33)">"D (a.z): %d</span=
><span style=3D"color:rgb(187,102,34);font-weight:bold">\n</span><span styl=
e=3D"color:rgb(186,33,33)">"</span>, other.z);
other.f1();
B<span style=3D"color:rgb(102,102,102)">::</span>f2();
}
};
<span style=3D"color:rgb(176,0,64)">void</span> <span style=3D"color:rgb(0,=
0,255)">takes_B</span>(<span style=3D"color:rgb(0,128,0);font-weight:bold">=
const</span> B<span style=3D"color:rgb(102,102,102)"><</span>A<span styl=
e=3D"color:rgb(102,102,102)">>&</span> b){
b.f2();
}
<span style=3D"color:rgb(176,0,64)">int</span> <span style=3D"color:rgb(0,0=
,255)">main</span>(){
D d{};
B b{};
b.f2();
printf(<span style=3D"color:rgb(186,33,33)">"=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D</span><span style=3D"color:rgb(187,102,34);font-weight:bold">\n</=
span><span style=3D"color:rgb(186,33,33)">"</span>);
d.f2();
printf(<span style=3D"color:rgb(186,33,33)">"=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D</span><span style=3D"color:rgb(187,102,34);font-weight:bold">\n</=
span><span style=3D"color:rgb(186,33,33)">"</span>);
takes_B(d);
<span style=3D"color:rgb(0,128,0);font-weight:bold">return</span> <span=
style=3D"color:rgb(102,102,102)">0</span>;
}</pre><br></div><div><br></div><div>I've even provided a takes_B funct=
ion to demonstrate how a D can be cast to a B (implemented in the second B =
constructor).<br><br></div><div>Take this code, try it out (you'll need=
c++17, otherwise to write B<> instead of B in the main function, rep=
lace std::enable_if_t<...> with std::enable_if<....>::type and =
std::is_base_of_v<...> with std::is_base_of<...>::value). Learn=
from it.<br><br>Then go away for a few years and come back when you're=
ready to contribute, preferably if you've learned some manners too. I =
believe I speak for the rest of us when I tell you that your attitude is ab=
solutely unwelcome here.<br></div></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/CAC%2B0CCM-vHkuqH6gu7J8Gk3GJMGaOuzUQb=
sdEFioRsx%2B8rbEpw%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter"=
>https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAC%2B0CCM-vH=
kuqH6gu7J8Gk3GJMGaOuzUQbsdEFioRsx%2B8rbEpw%40mail.gmail.com</a>.<br />
--000000000000f215af05732d5785--
.
Author: rmbeer2@gmail.com
Date: Sat, 11 Aug 2018 12:17:12 -0700 (PDT)
Raw View
------=_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 <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
*/
</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 << "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>------------------------------<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'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 ---------> 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 -----=
----> 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 << "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>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 << "A:" << a.z << 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 "a" with C+A, and also a variable "a"=
with A , being in class D a C+A, A, where the last A is not used, only C+A=
, in A it ends up using when the functions of B. are called.<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 <iostream><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 << "A:" << get_C_a().=
z << std::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 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 << "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 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, "C a;" =
of D replace "A a;" of B, in this way D only uses C+A from "=
C a;" and B only uses A from "A a;"<br><br>This is my propos=
al, a keyword like 'virtual' (or can be any other) in the variable =
of the same name that is replaced by the variable definition of the base cl=
ass.<br><br>Por ejemplo:<br>Code:<br>------------------------------<wbr>---=
------<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=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 << "A:" <&l=
t; a.z << 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 << "C+A:" &=
lt;< 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<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 -------> 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 << "A:" << a.z << 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 ---------> 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>--------------------=
----------<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 << =
"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>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 << "A:" << a.z=
<< 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 "a"=
con C+A, y tambien una variable "a" con A, siendo en la clase D =
un C+A,A , donde la ultima A no se usa, solo C+A , en A se termina usando 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 <iostream><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 << "A:" << get_C_a().z &=
lt;< std::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 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 << "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.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 "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, una=
palabra clave como 'virtual' (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 <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>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 << "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 {<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 << "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<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" 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--
.
Author: Jake Arkinstall <jake.arkinstall@gmail.com>
Date: Sat, 11 Aug 2018 20:42:05 +0100
Raw View
--0000000000001a450605732e0e97
Content-Type: text/plain; charset="UTF-8"
Rubbish - it CAN be done in modern C++. I gave you a working example of it.
Doing exactly what you want - being able to extend from something but
replacing a data type with a child class of itself - doesn't make any sense
in terms of memory allocation - but you can get exactly the same effect.
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAC%2B0CCOCMBqQqqHttP%3DZSaSUpYD_zSCS9axNj0yWzbvSrEjKOA%40mail.gmail.com.
--0000000000001a450605732e0e97
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div>Rubbish - it CAN be done in modern C++. I gave you a =
working example of it.<br><br>Doing exactly what you want - being able to e=
xtend from something but replacing a data type with a child class of itself=
- doesn't make any sense in terms of memory allocation - but you can g=
et exactly the same effect.<br></div></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/CAC%2B0CCOCMBqQqqHttP%3DZSaSUpYD_zSCS=
9axNj0yWzbvSrEjKOA%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter"=
>https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAC%2B0CCOCMB=
qQqqHttP%3DZSaSUpYD_zSCS9axNj0yWzbvSrEjKOA%40mail.gmail.com</a>.<br />
--0000000000001a450605732e0e97--
.