Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.
PrevUpHomeNext

Class access

boost::contract::access — Friend this class to declare invariants and base types as private members.

Synopsis

// In header: <boost/contract/core/access.hpp>


class access {
};

Description

Declare this class a friend of the user-defined class specifying the contracts in order to declare the invariant functions and the base types typedef as non-public members:

class u :
    #define BASES public b, private w
    BASES
{
    friend class boost::contract::access;

    typedef BOOST_CONTRACT_BASES(BASES) base_types; // Private.
    #undef BASES

    void invariant() const { ... } // Private.

public:
    ...
};

In real code, programmers will likely chose to declare this class as friend so to fully control public interfaces of their user-defined classes. This class is not intended to be directly used by programmers a part from declaring it friend (and that is why this class does not have any public member and it is not copyable).

[Warning] Warning

Not declaring this class friend of user-defined classes will cause compiler errors on some compilers (e.g., MSVC) because the private members needed to check the contracts will not be accessible. On other compilers (e.g., GCC and CLang), the private access will instead fail SFINAE and no compiler error will be reported while invariants and subcontracting will be silently skipped at run-time. Therefore, programmers must make sure to either declare this class as friend (preferred) or to always declare invariant functions and base types typedef as public members.

See Also:

Access Specifiers


PrevUpHomeNext