g++ 4.2.1 を使用してこのコードをコンパイルします。
struct S { };
template<typename T> struct ST { };
template<typename BaseType>
class ref_count : private BaseType { };
template<typename RefCountType>
class rep_base : public RefCountType { };
class wrap_rep : public rep_base<ref_count<S> > {
typedef rep_base<ref_count<S> > base_type; // line 11
};
私は得る:
bug.cpp:1: error: ‘struct S’ is inaccessible
bug.cpp:11: error: within this context
ただし、wrap_rep
使用するクラスを変更するとST
:
class wrap_rep : public rep_base<ref_count< ST<int> > > {
typedef rep_base<ref_count< ST<int> > > base_type;
};
それはうまくコンパイルされます。または、元のコードを次のように変更すると:
class wrap_rep : public rep_base<ref_count<S> > {
typedef rep_base<ref_count< ::S > > base_type; // now using ::
};
また、正常にコンパイルされます。私には、元のコードはそのままで問題ないようです。これは g++ のバグですか? そうでない場合、なぜテンプレートの使用が機能するのでしょうか? そして、他のケースでは、なぜ::S
必要なのですか?