From: Alf P. Steinbach on 10 Dec 2009 21:23 * Kaz Kylheku: > On 2009-12-11, Alf P. Steinbach <alfps(a)start.no> wrote: >> * Kaz Kylheku: >>> On 2009-12-11, Alf P. Steinbach <alfps(a)start.no> wrote: >>>>> On 2009-12-10, Alf P. Steinbach <alfps(a)start.no> wrote: >>>>>> You loose the ability to assert that you're overriding something >>>>>> existing. >>> [ ... ] >>> >>>> Nobody's said that you can assert that you're overriding, so that's a straw man >>> ? >> You're quoting the wrong context. >> >> In my first statement, the meaning of "overriding something existing" which I >> said one can do, was with the accent on the something existing, otherwise >> there'd be no point in adding those words; you know that you're overriding, >> you're asserting that the func you're overriding does exist in base class, and >> that assertion serves as documentation and guards against code changes. > > Okay, can you show how you are coding that? #define CPPX_IS_OVERRIDE_OF_0ARG( memberSpec ) \ ::cppx::suppressUnusedWarning( sizeof( (memberSpec(), 0) ) ) #define CPPX_IS_OVERRIDE_OF_1ARG( memberSpec, a1 ) \ ::cppx::suppressUnusedWarning( sizeof( (memberSpec(a1), 0) ) ) #define CPPX_IS_OVERRIDE_OF_2ARG( memberSpec, a1, a2 ) \ ::cppx::suppressUnusedWarning( sizeof( (memberSpec(a1, a2), 0) ) ) #define CPPX_IS_OVERRIDE_OF( memberSpec ) CPPX_IS_OVERRIDE_OF_0ARG( memberSpec ) Note that the macro name doesn't say what the macro does. It's just a documentation macro outfitted with some checking that doesn't hurt if what it documents is true. Instead of individual args you can better use just an arg-list argument, but the code above didn't start out that way and there's been no reason to fix it. > If we simply declare a function in a class which has bases, we don't > know whether or not that function is virtual; it could match a virtual > function in one of the bases, thereby inheriting that attribute > and overriding. > > If we explicitly make it virtual, we still don't know whether or not > something is being overridden, or whether it's a new virtual. > > We can inspect all the bases when we are coding this, but tomorrow, they > can change; someone can add a virtual function to a base such that > we already have an overriding function in the derived class. I think that's right, that there's no portable way to detect virtualness of a specific member routine in a C++98. > If there is a way of writing assertions for this sort of thing, or > anyting at all related to overriding or not-overriding; that could be > useful. (Compile time, or run-time). I don't think so, not in a portable way. Cheers & hth., - Alf
First
|
Prev
|
Pages: 1 2 3 4 Prev: Multiplying a complex number by a constant? Next: operator[] in a std::vector like class |