私はウェブを検索しましたが、次のことが起こる理由の説明が見つかりませんでした。
たとえば、ネストされたクラス Nested を含むテンプレート クラス Enclosing があります。
囲みクラスには、ネストされたクラスのインスタンスを作成し、そのフィールドとメソッドを使用するメソッドがあります。
次のコードには、私がそれをやろうとしている方法のモデルがあります:
template<typename T, typename S>
class Enclosing{
public:
class Nested;
Nested foo();
};
template<typename T, typename S>
class Enclosing<T,S>::Nested{
public:
T field;
void some_method();
friend class Enclosing; // instead of this line I also tried:
// friend class Enclosing<T,S>
// and it didn't work either
};
template<typename T, typename S>
typename Enclosing<T,S>::Nested Enclosing<T,S>::foo (){
Nested nes;
nes.some_method; // the problem appears here
return enc;
}
問題は:
私が書いているときnes.some_method
、私が試した環境(VS2010、Eclipse)のどれも、「nes.」と入力した後、オプションを提案しません。「nes」はクラスのインスタンスではないようです。
囲んでいるテンプレート クラスからネストされたクラスのメソッドとフィールドにアクセスする方法は?