3

このコードをコンパイルしようとすると:

template <class URNG>
struct Dumb : Brain<Dumb, URNG>
{
    Move operator()(const Rat<Dumb, URNG>& rat, URNG&& urng)
    {
        Move move;
        move.x = 1;
        move.y = 0;
        //rat.look(1, 2);
        //rat.getDna(35);
        return move;
    }
};

clang 3.2.7 raise、この奇妙なエラーがわかりません:

main.cpp:10:28: error: template argument for template template parameter must be a class template or type alias template
        Move operator()(const Rat<Dumb, URNG>& rat, URNG&& urng)
                                  ^

ダムはクラステンプレートですよね?

コメントで尋ねられたように、これはラットがどのように見えるかです:

template <template <class> class BRAIN, class URNG>
class Rat
{
//...
}
4

1 に答える 1

4

あなたの問題は、注入された名前が原因です:

template <class URNG>
struct Dumb : Brain<Dumb, URNG>
{
    // in here, "Dumb" refers to the complete type "Dumb<URNG>"
    Move operator()(const Rat<Dumb, URNG>& rat, URNG&& urng)
                          //  ^^^^ 
                          //  really a type, not a template

これを修正するには、注入されていない名前を参照する必要があります。これは次のように実行できます。

template <class URNG>
struct Dumb : Brain<Dumb, URNG>
{
    Move operator()(const Rat<::Dumb, URNG>& rat, URNG&& urng)
                          //  ^^^^^^
                          //  actual Dumb<T> template, not type
于 2015-01-24T14:45:57.643 に答える