Fausto Sanchez
Fausto Sanchez

Reputation: 542

Template and typedef errors

I've got this class:

template <class T>
class NodoLista
{
public:
    T dato;
    Puntero<NodoLista<T>> sig;
    NodoLista<T>(const T& e, Puntero<NodoLista<T>> s) : dato(e), sig(s)  { };
};

then i try using the typedef like this:

template <class U>
typedef Puntero<NodoLista<U>> pNodoLista;
void main()
{
    pNodoLista<int> nodo = new NodoLista<int>(1, nullptr);
    cout<<nodo->dato<<endl;
}

and I get an error saying that my template is incorrect. How can I use the typedef to use:

Puntero<NodoLista<T>> as pNodoLista<T>

Upvotes: 1

Views: 110

Answers (2)

songyuanyao
songyuanyao

Reputation: 173044

Try use

template <class T>
using pNodoLista = Puntero<NodoLista<T>>;

Now pNodoLista<T> is equivalent to Puntero<NodoLista<T>>.

LIVE

If your compiler doesn't support c++11, you can use a workaround:

template <class T>
struct pNodoLista
{
    typedef Puntero<NodoLista<T>> type;
};

Now pNodoLista<T>::type is equivalent to Puntero<NodoLista<T>>.

LIVE

BTW: main() should return int.

Upvotes: 0

πάντα ῥεῖ
πάντα ῥεῖ

Reputation: 1

template <class U>
typedef Puntero<NodoLista<U>> pNodoLista;

should be

typedef template <class U> Puntero<NodoLista<U>> pNodoLista;

Upvotes: 2

Related Questions