How to pass structures to template class functions

0

I just do not understand why you're wrong. This code works.

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;
}

But this one does not work.

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;
}
    
asked by anonymous 24.08.2017 / 21:35

1 answer

0

The syntax of your second code is completely wrong.

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;
}

This is the correct syntax, but I'd like to know what exactly you expect to achieve with this class. Are you studying templates?

    
28.08.2017 / 01:21