Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Andreas Leitgeb Newsgroups: comp.lang.java.programmer Subject: Re: How to assign an object to another in it method? Date: Mon, 3 Jul 2017 16:28:39 -0000 (UTC) Organization: A noiseless patient Spider Lines: 28 Message-ID: References: <46334961-cc18-491f-828c-32e7401c7832@googlegroups.com> Reply-To: avl@logic.at Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Injection-Date: Mon, 3 Jul 2017 16:28:39 -0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="d11154bb73ee01ffbd26915353679015"; logging-data="18038"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+VZ7QV0TbAqYMF4T2lJ5OE" User-Agent: slrn/1.0.2 (Linux) Cancel-Lock: sha1:PiONPWEVC6FCzJ8cparK1Z2RZt8= Xref: csiph.com comp.lang.java.programmer:36799 Jerry Stuckle wrote: > On 7/3/2017 10:04 AM, Andreas Leitgeb wrote: >> Arne Vajhøj wrote: >>> That is what I consider the missing default parameter issue. >>> // **** NOT JAVA **** >>> public Demo(String name, int answer = 6, boolean prisoner = false) >> Imho this is one thing that Java actually got right, by *not* supporting. >> In C++, default values can give a hard time when overiding methods with >> defaults, as the default value depends on the static target object >> type even for virtual methods. > And how so? It shouldn't happen if your design is correct. Not sure what you mean... Do you mean that one just shouldn't have a subclass giving different defaults for the override of a virtual method? Maybe. About 20 years ago, I had a case, where I thought it made sense, and iirc I then rewrote it to two separate methods and let the (ditto virtual) "no-args" overload call the "arg-taking" one with the subclass's overridden value - i.e. I ended up doing it like one would do it in Java, anyway - and back then, I didn't yet program Java. I still casually use defaults in my C++ projects, but only for non-virtual methods. And it's just syntactic sugar in those cases, and later I usually regret it, when I need to consult the .hpp file to see what really gets called - even within the same class.