Article View: alt.comp.lang.learn.c-c++
Article #89Re: virtual operator+
From: Christopher Deli
Date: Fri, 17 May 2002 08:51
Date: Fri, 17 May 2002 08:51
47 lines
3009 bytes
3009 bytes
"Karl Heinz Buchegger" <kbuchegg@gascad.at> skrev i meddelandet news:3CE4C209.7010606@gascad.at... > > > 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 > Can I create a member function which serves the same function as an operator (is it possible to write a = c + b?)? I tried to make a friend operator aswell but the same things happened.. Isn't it possible to change the static type of my pointer by type casting or something so it could be enough with and operator in the subclass? //Christopher
Technical Details
Message-ID:
<6w3F8.38349$n4.8445243@newsc.telia.net>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news.tele.dk!small.news.tele.dk!TeliaNet!194.22.194.4.MISMATCH!masternews.telia.net.!newsc.telia.net.POSTED!not-for-mailReferences:
<5mVE8.38287$n4.8427350@newsc.telia.net> <rg49eusfujq9l0nq0m5dimtbenu36m0lor@4ax.com> <VL2F8.38343$n4.8444053@newsc.telia.net> <3CE4C209.7010606@gascad.at>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: 10d4ba,e2ff40a616ce87ab X-Google-Attributes: gid10d4ba,public X-Google-Thread: 114592,e2ff40a616ce87ab X-Google-Attributes: gid114592,public X-Google-ArrivalTime: 2002-05-17 01:51:25 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news.tele.dk!small.news.tele.dk!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> <VL2F8.38343$n4.8444053@newsc.telia.net> <3CE4C209.7010606@gascad.at> Subject: Re: virtual operator+ Lines: 49 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: <6w3F8.38349$n4.8445243@newsc.telia.net> Date: Fri, 17 May 2002 08:51:14 GMT NNTP-Posting-Host: 212.181.175.64 X-Complaints-To: abuse@telia.com X-Trace: newsc.telia.net 1021625474 212.181.175.64 (Fri, 17 May 2002 10:51:14 CEST) NNTP-Posting-Date: Fri, 17 May 2002 10:51:14 CEST Organization: Telia Internet