🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: virtual operator+

#87
From: Karl Heinz Buchegger
Date: Fri, 17 May 2002 08:40
31 lines
2407 bytes

Christopher Deli 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.
> 


First of all: please don't top post.
Scroll to the section you want to reply to, and insert
your comments there.

As you have seen, there is a technical problem with having
an operator: the return type.
Are you sure you *must* implement an operator or will an
ordinary member function be sufficient?
If your assignment explicitely states an operator, then I
would suggest to ask your teacher, how he thinks this should
work (Hint: it is impossible, since operator+ has to return
an object, but for polymorphism you would need a pointer or
a reference).

-- 
Karl Heinz Buchegger
kbuchegg@gascad.at
Technical Details
Message-ID: <3CE4C209.7010606@gascad.at>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!fu-berlin.de!uni-berlin.de!62.46.208.145!not-for-mail
References: <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: 109fba,e2ff40a616ce87ab
X-Google-Attributes: gid109fba,public
X-Google-Thread: 114592,e2ff40a616ce87ab
X-Google-Attributes: gid114592,public
X-Google-Thread: 10d4ba,e2ff40a616ce87ab
X-Google-Attributes: gid10d4ba,public
X-Google-ArrivalTime: 2002-05-17 01:36:47 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!fu-berlin.de!uni-berlin.de!62.46.208.145!not-for-mail
From: Karl Heinz Buchegger <kbuchegg@gascad.at>
Newsgroups: alt.comp.lang.learn.c-c++,att.lang.c++,comp.lang.c++
Subject: Re: virtual operator+
Date: Fri, 17 May 2002 10:40:41 +0200
Organization: GASCAD
Lines: 32
Message-ID: <3CE4C209.7010606@gascad.at>
References: <5mVE8.38287$n4.8427350@newsc.telia.net> <rg49eusfujq9l0nq0m5dimtbenu36m0lor@4ax.com> <VL2F8.38343$n4.8444053@newsc.telia.net>
NNTP-Posting-Host: 62.46.208.145
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: fu-berlin.de 1021624606 23266738 62.46.208.145 (16 [95537])
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; de-DE; rv:0.9.4.1) Gecko/20020314 Netscape6/6.2.2
X-Accept-Language: de-DE