Error no match for 'operator *' (operand type is class)

0

I have the following code that performs the search in Rear order of a tree:

template<class T>
Lista<NodoArbol<T>>* Arbol<T>::ordenPosterior(NodoArbol<T>*origen,Lista<NodoArbol<T>>* OPos){
while(1){
    NodoArbol<T>* siguiente = *origen->getSiguiente();
    if(siguiente->getElemento()!=nullptr){
        ordenPosterior(siguiente,OPos);
        OPos->add(siguiente,OPos);
    }else{
        break;
    }
  }
}

I have the function getNext defined this way:

template <class T>
NodoArbol<T> NodoArbol<T>::getSiguiente(){
   return this->hijos->getValor(this->hijos,siguiente++);
}

In the NodoArbol children list, I put NodoArbol references to access the children of that node, the problem is presented in the line:

NodoArbol<T>* siguiente = *origen->getSiguiente();

With the following error:

..\src\Arbol.h:78:29: error: no match for 'operator*' (operand type is 'NodoArbol<Vertice>')

I'm new to this in the C ++ objects and I think I have a reference problem but I do not know how to identify which notation I should use if the reference to the class or the pointer to the reference

    
asked by Angel Bulnes 12.11.2017 в 02:36
source

1 answer

2

The error is clear and self-explanatory, maybe you do not understand it because it is in English, I translate it to you:

  

error: no match for 'operator*' (operand type is 'NodoArbol<Vertice>')

  

error: no hay coincidencia para 'operator*' (el tipo del operando es 'NodoArbol<Vertice>')

This error goes to say that the compiler has tried to use the de-reference operator ( * unary) on object NodoArbol<Vertice> and could not. This may be due to:

  • NodoArbol<Vertice> is not a type that natively supports the de-reference operator.
  • NodoArbol<Vertice> does not have a de-reference operator defined by the user.
  • It is undoubtedly the second case, the only types that support the de-reference natively are the pointers and NodoArbol<Vertice> is not a pointer type, so we only have the second case.

    Surely you wanted to access the node as such, since getSiguiente returns the node, you would already have it:

        template <class T>
        NodoArbol<T> NodoArbol<T>::getSiguiente(){
    //  ~~~~~~~~~~~~ <-- Devuelve Nodo, no devuelve puntero-a-Nodo!
           return this->hijos->getValor(this->hijos,siguiente++);
        }
    
    //   Sin des-referenciar --> vvvvvvvvvvvvvvvvvvvvvv
        NodoArbol<T> siguiente = origen->getSiguiente();
    //  ~~~~~~~~~~~~ Nodo, no puntero-a-Nodo
        if(siguiente.getElemento()!=nullptr){
    //              ^ <-- punto, no flecha
            ordenPosterior(siguiente,OPos);
            OPos->add(siguiente,OPos);
    
        
    answered by 13.11.2017 в 10:12