2

次のケースは、MS Visual Studioでは正常にコンパイルされますが、g++4.6ではコンパイルされません。

コンパイル:

    template <typename T>
    struct get_type
    { typedef void type_;};

template <>
    struct get_type<float>
    { typedef float type_; };

template <>
    struct get_type<int>
    { typedef int type_; };

template <typename T, typename P=get_type<T>::type_> // <--- line 16
    struct get_destroy_type
    { static inline void exec(P a) {} };

結果:

../testlibrary/testlibrary.h:16:34: error: expected type-specifier
../testlibrary/testlibrary.h:16:34: error: expected ‘&gt;’

使ったら気に入らないようです

get_type<T>::type_

テンプレート引数のデフォルトとして。MS Visual Studio(Express 10)は、これを正常にコンパイルします。これをコンパイルするためにg++を取得するためにどのような変更を加えることができますか?

4

1 に答える 1

6

typename曖昧さ回避に使用:

template <typename T, typename P = typename get_type<T>::type_>
                                   |______|
于 2012-11-01T19:29:20.593 に答える