Boost logo

Boost :

From: Dan W. (danw_at_[hidden])
Date: 2004-01-08 14:17:37

Daniel Wallin wrote:
> Dan W. wrote:
>> It's been suggested to me that introducing inheritance and
>> virtual functions via inheritance in debug mode might not be
>> good ideas. Note however that,
>> (A) as of version 1.01 there is no longer size augmentation
>> via inheritance, since the only data member was removed.
> Yes there is, there's still a virtual member function.

I meant no "size augmentation" in the sense of sizeof(a_class) being
different from sizeof("a_class : invariants< a_class >").

>> (B) also as of version 1.01 private inheritance is used.
>> (C) class invariants is templeted per derived, and therefore
>> does not conduce to unwanted sibling relationships
>> (D) the only virtual function inherited from invariants class
>> is check_invariants(), which is pure virtual in the base,
>> and no longer virtual in derived. This AFAIK should not
>> cause the compiler to generate an otherwise absent virtual
>> table.
>> (E) Using inheritance allows one to use succint class member
>> names in the invariant assertions, rather than have to
>> dereference a pointer, or reference via '.'.
> From my implementation:
> struct my_type
> {
> private:
> friend class invariant_access;
> void invariant() const
> {
> ...
> }
> };
> I don't see how it's related to inheritance. Or did you mean something
> else?

I must have meant something else, since I don't understand what you're
trying to tell me.
What I say in (E), if that's what you're not sure what I mean, is that if

class my_class
    int a, b, c;
    struct check_invariants
       void check( my_class const & );
    friend class check_invariants;

then I need to de-reference members when writing assertions...

void my_class::check_invariants::check( my_class const & _ )
    assert( _.a + _.b == _.c );

I find it more intuitive for check() to be a member function.

Boost list run by bdawes at, gregod at, cpdaniel at, john at