Mathias Bauer schrieb:
Nikolai Pretzell wrote:

I'd however like to establish a rule that classes/functions taking a
pointer to (possibly) not fully constructed classes have a comment that
explicitely allows that - assuming that everywhere else it is a bug.

Is a cast to the base class when passing "this" enough? Something like


A cast isn't really a comment. And Nikolai meant that the *recipient* of the argument must be commented, telling in its header documentation (e.g. the autodoc stuff that should be there) that this use is valid. By commenting callers you don't prevent maintenance changes from breaking the callers' assumptions.

aControllElement((Window*)this, MyRedId )

instead of the current

aControllElement(this, MyRedId )

though I consider this to be superfluous in case of VCL Windows because
*they work this way*. Why commenting something that works as designed?


Using a cast where an implicit version would do is rarely a good idea, but if it does add information, it should be a static cast. A C-style cast is the worst choice here. For example if the class of *this were changed to not be derived from Window any more, the C-style cast would silently become a reinterpret_cast and the now invalid code would still compile.

Additionally I don't see how using a cast here can be construed to be a comment that unambiguously states that the constructor of aControllElement allows passing a not fully constructed object?

Here I would see it from the other side: the ctor implementation of
"aControlElement" had a serious bug if it would call any virtual methods
on the "parent" pointer it gets passed in.


That is the case, if this restriction is part of the semantics of that constructor. I assume you mean that any VCL Window/Control class is required to offer this kind of semantics!? In that case there should be documentation somewhere (an appropriate common base class?) that states this, and Nikolai's suggestion is that the header for the class of aControllElement should reiterate that it implements that self-restriction.

- Jörg


--
Joerg Barfurth              Sun Microsystems - Desktop - Hamburg
>>>>>>>>>>>>>>>>>> using std::disclaimer <<<<<<<<<<<<<<<<<<<<<<<
Software Engineer                         [EMAIL PROTECTED]
OpenOffice.org Configuration          http://util.openoffice.org

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to