0

Eu simplesmente não entendo porque esta errado. Este código funciona.

template
class test{
public:
    struct st1{
        T a, b, c;
    };
    struct st2{
        T d, e, f;
    };

    T foo1(st1 *st);
    st1 *foo2();
};

template
typename test::st1 *foo2()
{
    return 0;
}

template
T test::foo1(typename st1 *st)
{
    return 0;
}

Mas este não funciona.

template
class test{
public:
    struct st1{
        T a, b, c;
    };
    struct st2{
        T d, e, f;
    };

    T foo1(st1 *st);
    st1 *foo2();
    st1 *foo3(st2 *st);
};

template
T test::foo1(typename st1 *st)
{
    return 0;
}

template
typename test::st1 *foo2()
{
    return 0;
}

template
typename test::st1 *foo3(typename st1 *st)
{
    return 0;
}
1

1 Resposta 1

0

A sintaxe do seu segundo código está completamente errada.

template <typename T>
class test{
public:
    struct st1{
        T a, b, c;
    };
    struct st2{
        T d, e, f;
    };

    T foo1(st1 *st);
    st1 *foo2();
    st1 *foo3(st2 *st);
};

template <typename T>T test<T>::foo1(st1 *st)
{
    return 0;
}

template <typename T> typename test<T>::st1* test<T>::foo2()
{
    return 0;
}

template <typename T> typename test<T>::st1* test<T>::foo3(st2 *st)
{
    return 0;
}

Esta é a sintaxe correta, mas gostaria de saber o que exatamente você espera conseguir com esta classe. Você está estudando templates?

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .