Article View: borland.public.cppbuilder.oodesign
Article #127Taking operator overloading too far?
From: Andrue Cope [TeamB]
Date: Tue, 01 Feb 2005 14:29
Date: Tue, 01 Feb 2005 14:29
32 lines
2248 bytes
2248 bytes
I am currently designing an application that will process a source and
validate its contents by recalculating an MD5 for everything it
contains. The user can optionally provide a second source and have the
contents of that compared against the first.
In one configuration this equates to comparing two directory trees and
I had this idea of overloading the '==' operator for the class that we
already have that we use to iterate directory trees.
In pseudo code this might be:
TOVolIO_DirectoryTree src( "c:\\" ),
trg( "d:\\" );
if( src==trg )
ShowMessage( "The directory trees are identical" );
The main objection I have to this is that if you overload '=='
shouldn't you also overload '>' etc. (and what would '>' mean in this
context come to that)? I know that the language doesn't require it (in
the sense that as long as no one tries to use them there's no problem)
but I've always felt that if you overload one relational operator it is
best practice to overload them all.
The other objection I have is perhaps even more trivial. It somehow
feels 'wrong' to have calling an operator result in such a large amount
of activity. Then again the algorithm almost writes itself since of
course the file handling objects will also have an '==' overload.
--
Andrue Cope [TeamB]
[Bicester, Uk]
http://info.borland.com/newsgroups/guide.html
Technical Details
Message-ID:
<41ff924d@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!proxad.net!proxad.net!194.117.148.138.MISMATCH!pe2.news.blueyonder.co.uk!blueyonder!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 10db1e,6c4cb604a6b19d7,start X-Google-Attributes: gid10db1e,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Andrue Cope [TeamB]" <no.spam@not.a.valid.address> Subject: Taking operator overloading too far? Newsgroups: borland.public.cppbuilder.oodesign User-Agent: XanaNews/1.17.1.2 MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 NNTP-Posting-Host: 217.207.223.34 Message-ID: <41ff924d@newsgroups.borland.com> Date: 1 Feb 2005 06:29:33 -0800 X-Trace: newsgroups.borland.com 1107268173 217.207.223.34 (1 Feb 2005 06:29:33 -0800) Lines: 32 X-Authenticated-User: acope Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!proxad.net!proxad.net!194.117.148.138.MISMATCH!pe2.news.blueyonder.co.uk!blueyonder!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail