0
Guys, I’m implementing a stack with C++ pointers and have the following code for now:
template <class T>
struct Node {
T item;
Node *prox;
};
class Pilha {
private:
int tamanho;
Node *topo;
public:
Pilha() {
this->topo=NULL;
this->tamanho=0;
}
In the private attribute top, the guy Node is not being recognized within my class Stack. The eclipse returns the following error: Type 'Node' could not be resolved.
What can it be? Thank you!
I have to put the <T> in the *Node top , both in struct qnt in private attribute in stack? Obg!
– lineOut
@lineout Yes, because every time you use a template value in a class, the class has to switch to template as well, otherwise you couldn’t specify that you wanted a template
Pilha<int>
or aPilha<double>
. In that case when instancePilha<int>
will forceNode<int>
.– Isac
I did it but inside the stack ta returning error: Type 'Node<T>' could not be resolved ... even though I also put the template indication in the Stack. In the struct there was no error.
– lineOut
@lineout See the code example in my error free answer in Ideone. I even left an instantiation of a new node in the constructor as an example.
– Isac
It worked... Thanks @Isac !! ^^
– lineOut