<p>void bar (QIODevice& zzz)<br>
{<br>
    // ...<br>
    zzz.close(); // Oops<br>
}</p>
<p>void foo ()<br>
{<br>
    QTemporaryFile file;<br>
    bar(file);<br>
}</p>
<p>The function bar() may be replaced by anything that doesn't care what type I/O object to work with (e.g. QDataStream). "Why the hell does a function close an object owned by something else?" is another question, but the idea as a whole is simple and obvious -- if a function works with a base class (e.g. anything that can act as an I/O device, be it an actual file, memory buffer, etc.), the hint "don't call this method because in one of derived classes it does not what the name implies" doesn't work.</p>

<div class="gmail_quote">On Aug 24, 2013 2:05 PM, "Till Oliver Knoll" <<a href="mailto:till.oliver.knoll@gmail.com" target="_blank">till.oliver.knoll@gmail.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div dir="auto"><div>Am 24.08.2013 um 09:46 schrieb Constantin Makshin <<a href="mailto:cmakshin@gmail.com" target="_blank">cmakshin@gmail.com</a>>:</div><div><br></div><blockquote type="cite"><div><p>Overriding a public method to make it private doesn't make much sense because this restriction can be easily circumvented by casting the pointer/reference to a base class (explicitly or by passing it to a function, in the context of this thread, expects a QFile or even more generic QIODevice).</p>

</div></blockquote><div>Casting? Pointers? Why so complicated?</div><div><br></div><div>C++ makes this easy for you:</div><div><br></div><div>#define private public</div><div>#include "Foo.h"</div><div><br></div>

<div>There you go: all private members of class Foo have just become public! A hip hip horray for the preprocessor ;)</div><div><br></div><div>Oh, by the way: should you feel the urge to pass on this "tip" to someone else: please don't mention my name, will you? ;)</div>

<div><br></div><div><br></div><div>But on a more serious note: overriding a public method and make it private is more like a "design decision" and a strong hint to the caller not to call this member on that concrete class instance anymore: why not? Go read the docs! (And if you still feel like calling it: C++ offers you plenty of choices ;))</div>

<div><br></div><div>Cheers,</div><div>  Oliver</div><div><br></div><div><br></div></div><br>_______________________________________________<br>
Interest mailing list<br>
<a href="mailto:Interest@qt-project.org" target="_blank">Interest@qt-project.org</a><br>
<a href="http://lists.qt-project.org/mailman/listinfo/interest" target="_blank">http://lists.qt-project.org/mailman/listinfo/interest</a><br>
<br></blockquote></div>