Let's say I have a C++ class template:
template <class _T>
class MyClass
{
public:
int func();
private:
_T internal;
};
I'd like a way to specify a boolean to this template that, when true, will make every member in this template public.
For example:
MyClass<SomeClass, false> c1;
c1.internal.someFunc(); // ERROR
MyClass<SomeOtherClass, true> c2;
c2.internal.someFunc(); // SUCCESS
For those wondering, I'm using gtest and gmock to mock up concrete classes. So, in one of my unit tests I will have something like:
TEST(MyClass, Test1) {
MyClass<SomeMockClass, true> c1;
EXPECT_CALL(c1.internal, someFunc()).Times(1);
}
For this test template, internal must be accessible by my code. In production, I'd like to hide that from the user.
I'm using msvc 11 (Visual Studio 2012), so I have access to some C++11 features and metaprogramming constructs.