Article View: be.comp.programming
Article #2392Re: Trying to overload the << operator using C++
From: Matata
Date: Wed, 09 Jun 2004 19:13
Date: Wed, 09 Jun 2004 19:13
38 lines
2510 bytes
2510 bytes
On Wed, 09 Jun 2004 07:32:21 +0200, Aquila wrote:
> Jim wrote:
>
>> bag container[bags_to_use];��//�A�declared�bag�of�arrays.
>>
>>
>>
>
> you don't want to write an output operator for just this array right?
>
>> ostream& operator <<(ostream& outs, const bag& container[bags_to_use])
>> {
>>
>> stuff I will write later.
>>
>> }
>>
>> but I think that I may be wrong?��Is�my�syntax�wrong?
>>
> I don't think it's possible to have a variable array size in a definition...
> if it does work: did you put this operator in your class? what errors do you
> get?
It is perfectly possible. An array is a pointer to the first element in
c++. Just leave the [], and do some pointer arithmetic...
ostream& operator <<(ostream& outs, bag* container);
It is though easier to use a vector, and traverse with iterators.
vector <bag> container;
ostream& operator <<(ostream& outs, const vector<bag>& container);
If you place the << operator in your class declaration you will need a
friend with ostream. I don't think it is necessary if you don't place it
in the declaration of your bag class.
Greetz Matata
Technical Details
Message-ID:
<pan.2004.06.09.19.13.27.12756@NOSPAM.pi.be>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local1.nntp.dca.giganews.com!nntp.scarlet.biz!news.scarlet.biz.POSTED!not-for-mailReferences:
<2in1o6Fpl2ivU1@uni-berlin.de> <bJ6dndafgsV4PVvdRVn-vg@scarlet.biz>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII X-Google-Thread: fcea4,a23b69b2c15cdca2 X-Google-Attributes: gidfcea4,public Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local1.nntp.dca.giganews.com!nntp.scarlet.biz!news.scarlet.biz.POSTED!not-for-mail NNTP-Posting-Date: Wed, 09 Jun 2004 14:13:27 -0500 From: Matata <koen@NOSPAM.pi.be> Subject: Re: Trying to overload the << operator using C++ Date: Wed, 09 Jun 2004 21:13:27 +0200 User-Agent: Pan/0.14.2 (This is not a psychotic episode. It's a cleansing moment of clarity.) Message-ID: <pan.2004.06.09.19.13.27.12756@NOSPAM.pi.be> Newsgroups: be.comp.programming References: <2in1o6Fpl2ivU1@uni-berlin.de> <bJ6dndafgsV4PVvdRVn-vg@scarlet.biz> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit Lines: 38 NNTP-Posting-Host: 212.239.144.212 X-Trace: sv3-3tIfFqJRTi5BN1cOue6AmSn0vyfQH4oGdnMRn2J/Ux7+5xZHfNQECILgOHfYYBUGgD5Dog6XY6n0EST!bm3j02m43ZaQsPO3wdY91S2OHCXWKsbm1wgcapLp4jR1Z8L5krgXMZmXaaLHRbzwUf5pyLL1A8Sn!a4gAfdenC46/ X-Complaints-To: abuse@scarlet.be X-DMCA-Complaints-To: abuse@scarlet.biz X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.1