他のクラスBarで「直接」アクセスする必要があるクラスFooがあります。Bar のメソッド (Foo のフレンド メソッド) が保護されていることを宣言する小さなフレームワークを構築したいと思います。このようにして、Bar の子クラスをいくつか作成することができました。
Gccはそれについて不平を言い、メソッドがパブリックである場合にのみ機能します。
どのようにできるのか?私のコードの例:
class Foo;
class Bar {
protected:
float* internal(Foo& f);
};
class Foo {
private:
//some data
public:
//some methods
friend float* Bar::internal(Foo& f);
};
GCC メッセージ:
prog.cpp:4:16: error: ‘float* Bar::internal(Foo&)’ is protected
float* internal(Foo& f);
^
prog.cpp:11:43: error: within this context
friend float* Bar::internal(Foo& f);
^