🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: alt.comp.lang.learn.c-c++
Article #86

Re: virtual operator+

#86
From: Christopher Deli
Date: Fri, 17 May 2002 07:59
39 lines
2850 bytes
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.

// Christopher
"Josh Sebastian" <curien@cox.net> skrev i meddelandet
news:rg49eusfujq9l0nq0m5dimtbenu36m0lor@4ax.com...
> On Thu, 16 May 2002 21:17:53 GMT, "Christopher Deli"
> <christopher@delinfo.com> wrote:
>
> >Hello!
> >
> >I have a problem which I'd need some help with, please.
> >If I have one class A which is inherited by another class B i.e. class B
:
> >public class A and I would like to make a virtual operator+ in both class
A
> >and B so I could do the following:
> >A *a, *b, *c
> >a = new B(...)
> >b = new B(...)
> >c = new B(...)
> >*c = *a + *b
> >So I make a pointer of type A which points on an objekt of type B. For
that
> >I'd need a virtual operator+ but I have no idea how to make it. Please
help!
> >The source code of a program which has the similar situation would be
> >perfekt! Thanks!
>
> If you did this, then *a + *b could mean something (very) different
> from *b + *a. That's not a good idea, generally. Perhaps you shouldn't
> use an overloaded operator, in this circumstance.
>
> Josh
Technical Details
Message-ID: <VL2F8.38343$n4.8444053@newsc.telia.net>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news.tele.dk!small.news.tele.dk!213.204.128.162!news000.worldonline.se!TeliaNet!194.22.194.4.MISMATCH!masternews.telia.net.!newsc.telia.net.POSTED!not-for-mail
References: <5mVE8.38287$n4.8427350@newsc.telia.net> <rg49eusfujq9l0nq0m5dimtbenu36m0lor@4ax.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 114592,e2ff40a616ce87ab
X-Google-Attributes: gid114592,public
X-Google-Thread: 109fba,e2ff40a616ce87ab
X-Google-Attributes: gid109fba,public
X-Google-Thread: 10d4ba,e2ff40a616ce87ab
X-Google-Attributes: gid10d4ba,public
X-Google-ArrivalTime: 2002-05-17 00:59:52 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news.tele.dk!small.news.tele.dk!213.204.128.162!news000.worldonline.se!TeliaNet!194.22.194.4.MISMATCH!masternews.telia.net.!newsc.telia.net.POSTED!not-for-mail
From: "Christopher Deli" <christopher@delinfo.com>
Newsgroups: alt.comp.lang.learn.c-c++,att.lang.c++,comp.lang.c++
References: <5mVE8.38287$n4.8427350@newsc.telia.net> <rg49eusfujq9l0nq0m5dimtbenu36m0lor@4ax.com>
Subject: Re: virtual operator+
Lines: 41
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2600.0000
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000
Message-ID: <VL2F8.38343$n4.8444053@newsc.telia.net>
Date: Fri, 17 May 2002 07:59:49 GMT
NNTP-Posting-Host: 212.181.175.40
X-Complaints-To: abuse@telia.com
X-Trace: newsc.telia.net 1021622389 212.181.175.40 (Fri, 17 May 2002 09:59:49 CEST)
NNTP-Posting-Date: Fri, 17 May 2002 09:59:49 CEST
Organization: Telia Internet