2015-09-28 1 views
5

は、次のC++のコードを考えてみましょ専門(友人としてテンプレートクラス)のインスタンス化後:グラム++エラー:

それは、マイクロソフトのビジュアルC++コンパイラで動作します:

template <class T> 
class Singleton {}; 

class ConcreteSingleton : public Singleton<ConcreteSingleton> { 
    template <class T> 
    friend class Singleton; 
}; 

int main() {} 

Singleton友人ConcreteSingletonしなければなりません。しかし、私はg ++ 4.8.4でコンパイルできません。エラーは次のとおりです。

error: specialization of ‘Singleton<ConcreteSingleton>’ after instantiation 
     template <class T> friend class Singleton; 

これを修正する方法はありますか?

+2

ああ、このgccのバグ(https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52625)のようです。 – sergej

+1

Xcodeでうまく動作します(Apple LLVM 7.0 with C++ 14) –

+1

g ++ 5.2.0でもコンパイルに失敗します。 clangで動作します。 – user2079303

答えて