
Hello all, In the _many_ Contract Programming references that I have read (including N1962): http://contractpp.svn.sourceforge.net/viewvc/contractpp/trunk/doc/html/contr... I didn't find anything special about contracts for nested classes. I think that is because nested classes are executed at run-time "orthogonally" with respect to their enclosing classes. In other words, nesting a class only nests it's name (and changes some visibility rules) but it does not effect the run-time execution of the class and therefore it does not affect the contracts checked for the nested class. For example, the execution of a nested class y should only check y's invariants and not also the invariants of its enclosing class x: #include <contract.hpp> #include <iostream> CONTRACT_CLASS( struct (x) // enclosing class ) { CONTRACT_CLASS_INVARIANT( std::cout << "x's invariant" << std::endl ) CONTRACT_CLASS( public struct (y) // nested class ) { CONTRACT_CLASS_INVARIANT( std::cout << "y's invariant" << std::endl ) CONTRACT_FUNCTION( public void (f) ( void ) ) {} }; }; int main ( void ) { x::y yy; yy.f(); // checks y's invariant but not x's invariant return 0; } In fact in this example an object of x is not even created. Of course, if y was to create or get an object of x and invoke x's member functions then x's contracts will be checked as usual. This makes sense to me but I thought to share it with the ML. Thanks. --Lorenzo -- View this message in context: http://boost.2283326.n4.nabble.com/boost-contract-nothing-special-about-nest... Sent from the Boost - Dev mailing list archive at Nabble.com.
participants (1)
-
lcaminiti