Article View: alt.comp.lang.learn.c-c++
Article #92Re: virtual operator+
From: Daniel T.
Date: Fri, 17 May 2002 12:09
Date: Fri, 17 May 2002 12:09
48 lines
2627 bytes
2627 bytes
"Christopher Deli" <christopher@delinfo.com> wrote:
>The thing is that the assignment I am working with demands that I have a
>base class A with two subclasses (B and C) and I need to make ONE list
>with both B and C objects. A should be an abstract class. So I need to
>create an A pointer which sometimes points on B objects and sometimes on C
>objects. And on top of that I need an operator which can add two B
>objects. If I only put the operator in class B it wont work if the
>pointers I try to add have static type A and dynamic type B.
You want this?
int main() {
A* var1 = new B;
A* var2 = new B;
B result_b = *var1 + *var2;
delete var1;
delete var2;
var1 = new C;
var2 = new C;
C result_c = *var1 + *var2;
}
If so, what should happen if var1 is of dynamic type B and var2 is of
dynamic type C? (or vise-versa?)
Or do you want this?
int main() {
A* var1 = new B;
A* var2 = new B;
A result = *var1 + *var2;
delete var1;
delete var2;
var1 = new C;
var2 = new C;
result = *var1 + *var2;
}
If so, please understand that your result will be loosing information.
An 'A' object cannot hold all the information that a B or C object can.
Are you sure you have to be able to add two dereferenced A* objects
together? Maybe you only need to be able to add two B objects.
Technical Details
Message-ID:
<notdanielt3-9A6FDA.08091617052002@news.verizon.net>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed1.cidera.com!Cidera!cyclone1.gnilink.net!spamfinder.gnilink.net!nwrddc02.gnilink.net.POSTED!3fa03609!not-for-mailReferences:
<5mVE8.38287$n4.8427350@newsc.telia.net> <rg49eusfujq9l0nq0m5dimtbenu36m0lor@4ax.com> <VL2F8.38343$n4.8444053@newsc.telia.net>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10d4ba,e2ff40a616ce87ab X-Google-Attributes: gid10d4ba,public X-Google-Thread: 114592,e2ff40a616ce87ab X-Google-Attributes: gid114592,public X-Google-Thread: 109fba,e2ff40a616ce87ab X-Google-Attributes: gid109fba,public X-Google-ArrivalTime: 2002-05-17 05:27:38 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed1.cidera.com!Cidera!cyclone1.gnilink.net!spamfinder.gnilink.net!nwrddc02.gnilink.net.POSTED!3fa03609!not-for-mail From: "Daniel T." <notdanielt3@gte.net> Newsgroups: alt.comp.lang.learn.c-c++,att.lang.c++,comp.lang.c++ Subject: Re: virtual operator+ References: <5mVE8.38287$n4.8427350@newsc.telia.net> <rg49eusfujq9l0nq0m5dimtbenu36m0lor@4ax.com> <VL2F8.38343$n4.8444053@newsc.telia.net> User-Agent: MT-NewsWatcher/3.0 (PPC) Message-ID: <notdanielt3-9A6FDA.08091617052002@news.verizon.net> Lines: 48 Date: Fri, 17 May 2002 12:09:18 GMT NNTP-Posting-Host: 67.212.72.237 X-Complaints-To: abuse@verizon.net X-Trace: nwrddc02.gnilink.net 1021637358 67.212.72.237 (Fri, 17 May 2002 08:09:18 EDT) NNTP-Posting-Date: Fri, 17 May 2002 08:09:18 EDT