#include "access_protected_functions.hpp" #include class X { protected: void foo() const { std::cout << "X::foo() const\n"; } long bar(int i) { std::cout << "X::bar(" << i; return i + 1; } void doesnt_work(char,int); void doesnt_work(int,char); }; class Y : protected X { }; DECLARE_ACCESS_PROTECTED_FUNCTIONS( (foo)(bar)(doesnt_work) ) int main() { X x; ACCESS_PROTECTED_FUNCTION(X, x, foo, () ); long r1 = ACCESS_PROTECTED_FUNCTION(X, x, bar, (4) ); std::cout << ") => " << r1 << '\n'; Y y; ACCESS_PROTECTED_FUNCTION(Y, y, foo, () ); long r2 = ACCESS_PROTECTED_FUNCTION(X, x, bar, (7) ); std::cout << ") => " << r2 << '\n'; // This shoudn't compile because Y is expected: // ACCESS_PROTECTED_FUNCTION(Y, x, foo, () ); // If you want to change this, DIY: // ACCESS_PROTECTED_FUNCTION(Y, y, doesnt_work, (0, 0) ); }