Path: csiph.com!news.mixmin.net!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: Tim Rentsch Newsgroups: comp.lang.c++ Subject: Re: rational numbers Date: Wed, 06 Oct 2021 13:06:32 -0700 Organization: A noiseless patient Spider Lines: 35 Message-ID: <86ee8xrk8n.fsf@linuxsc.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: reader02.eternal-september.org; posting-host="f63a7b6827eb8960d7c84af554cfeab9"; logging-data="917"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+MHbgO0D5kHjV51v4BClE6LCj6RFFxOTM=" User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux) Cancel-Lock: sha1:yT1ralSkNxGWOonzcexHq36vgnk= sha1:W2JU3pAiS85AVMXiOyDShoEvDFo= Xref: csiph.com comp.lang.c++:81881 Juha Nieminen writes: > alessandro volturno wrote: > >> Il 17/09/2021 07:36, Juha Nieminen ha scritto: >> >>> alessandro volturno wrote: >>> >>>> printDescription() // prints a description of the number and its >>>> // numerical value >>> >>> This is not really something that belongs to a class that behaves >>> like an arithmetic numerical value. >>> >>> At most what you could have is a separate >>> >>> std::ostream& operator<<(std::ostream&, YourRationalClass); >>> >>> function for outputting the value to a std::ostream. >> >> if you read the two lines right before the one here reported you >> can see I did that. >> >> I wrote that function to give an extensive description of a >> rational number in a way like this: >> >> "4/16 reduces to 1/4 and evaluates to 0.25" > > I still think that designwise such a function does not belong in > that class. That depends on exactly what the function does. If the function depends on the object's internal representation or on invariants that are not publically available, then certainly defining the function as a member function is a more natural choice.