Ran into bizarre vc++ error, minimal example code:
int snafu;
struct Foo { static int snafu; };
int Foo::snafu;
struct Mid : private Foo {};
struct Bar : Mid {
void really() { snafu = 7; } // error C2247: 'Foo::snafu' not accessible because 'Mid' uses 'private' to inherit from 'Foo'
};
The error is nonsense - implementer of Bar should not know/care about private internals of Mid. Reported the problem - but obviously cannot wait for a fix. Any idea how to work around this problem?
Background:
* 'snafu' is actually a context specific logger instance - the global instance is ... well ... for generic fallback context when there is no need for having a context specific one.
* Mid is not a Foo, Mid has/shares a Foo implementation. Similar to composition.
* Composition is not an usable alternative as it would need friending a lot of classes dealing with Foo part of Mid who currently do not even know/care about there being a Mid or whatever else.
edit:
Oh, ffs.
I guess having to describe the problem to others helps.
Workaround: add a static reference in Bar to global snafu. Ie: int &Bar::snafu = snafu.
Have not yet tested it, but pretty sure it will work.
edit:
Yes, it does work. Annoying that i have to do it, but oh well.