Path: csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Ian Collins Newsgroups: comp.lang.c++ Subject: Re: Help needed Date: Sun, 5 Apr 2020 07:35:11 +1200 Lines: 56 Message-ID: References: <66b94985-7db1-41e1-98f7-e509c5a0a142@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net 4g9k7V7UPYI1490/EY+3mgMePu5f5RdxdBZZuHAUN8EWdERx2p Cancel-Lock: sha1:7f1OweSBGqoA1vzM2bDqloVnKwU= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.4.1 In-Reply-To: Content-Language: en-US Xref: csiph.com comp.lang.c++:72811 On 05/04/2020 02:33, Ned Latham wrote: > Alf P. Steinbach wrote: > >> Here's an example: >> >> >> #include >> using namespace std; // Do this to get roughly pre-standard behavior. > > Not me. Namespace is beyond the pale. > >> struct Non_native >> { >> double amount; >> >> operator double() const { return amount; } > > What's this for? It's not used, below. It is. >> >> void advance() >> { >> amount += 0.01; >> } >> >> Non_native operator++( int ) > > double is non-native? > >> { >> Non_native result = *this; >> advance(); >> return result; >> } >> }; >> >> int main() >> { >> Non_native o = {3.14}; >> >> cout << "Originally " << o++ << "." << endl; >> cout << "After: " << o << "." << endl; >> } > > I'm not even going to try it, Alf, And I bet you haven't done so. > That code requires overload operators = and << for the struct. > No, it doesn't. The code compiles and behaves exactly as intended and your inability to comprehend it clearly demonstrates what I thought all along, you are clueless. -- Ian.