我有一種難題我試圖理清,而不必公開暴露關鍵部分。整理出C++繼承訪問保護難題
template<class Feature>
struct Fixture {
private:
Feature f;
protected:
Fixture() : f() {}
public:
Feature* const get() { return &f; }
};
struct MyFeature {
protected:
MyFeature() {}
};
struct FixtureHost : public Fixture<MyFeature> {
};
至少使用微軟的Visual C++編譯器2015年,我相處C2248的線路錯誤,「我的功能::我的功能」:不能訪問類「我的功能」宣佈受保護的成員。
我想要訪問功能以及要保護的夾具訪問權限。真的,只有FixtureHost或友誼圈內的東西才能被允許實例化它們中的任何一個。
但是對於舊的C++編譯器來說,這看起來太過分了?如果我必須公開公開構造函數,那就這樣做吧,但是我想避免它。
[朋友](http://en.cppreference.com/w/cpp/language/friend)? – happydave
'朋友燈具;' –
George
請發表[MCVE](http://stackoverflow.com/help/mcve) –