Reputation: 542
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
Reputation: 173044
Try use
template <class T>
using pNodoLista = Puntero<NodoLista<T>>;
Now pNodoLista<T>
is equivalent to Puntero<NodoLista<T>>
.
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>>
.
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