- status changed from new to accepted
Why "hard"? (For example, take a look to what Boost.Parameter requires
to deal with constructs...)
You can just program the constructors with member initializers in the
class declarations when using contracts:
CONTRACT_CLASS(
class (x)
) {
CONTRACT_CLASS_INVARIANT( void )
CONTRACT_CONSTRUCTOR(
public (x) ( void )
initialize( a_(1), b_(2), c_(3) )
) {
... // body right here
}
private: int a_, b_, c_;
};
If the body is really just too complex for an header... then you can
always separate it with an init function (essentially, only the
initializer list remains in the class declaration):
CONTRACT_CLASS(
class (x)
) {
CONTRACT_CLASS_INVARIANT( void )
CONTRACT_CONSTRUCTOR(
public (x) ( void )
initialize( a_(1), b_(2), c_(3) )
) {
init(); // simple body
}
private: void init ( void ); // deferred
private: int a_, b_, c_;
};
// possibly in another file...
void x::init ( void )
{
... // body now here (far from the declaration)
}
Log in to post a comment.