Problem when compiling Invert content from a list

1

I've done a list exercise that does not work out for me, it's this:

  

Develop the template method <class T> void dll_t<T>::invert(void) that reverses the order of the values of a list on itself (without using auxiliary list).

this is the code:

#pragma once

#include <cassert>
#include <iostream>
#include <cstdio>

#include "dll_node_t.hpp"

using namespace std;

namespace AED {

    template <class T>
    class dll_t {
    private:
        dll_node_t<T>* head_;
        dll_node_t<T>* tail_;

        int sz_;

    public:
        dll_t(void);
        dll_t(const dll_t& L);
        virtual ~dll_t(void); 

        void insert_tail(dll_node_t<T>*);
        void insert_head(dll_node_t<T>*);

        dll_node_t<T>* extract_tail(void);
        dll_node_t<T>* extract_head(void);

        dll_node_t<T>* get_tail(void);
        dll_node_t<T>* get_head(void);

        bool empty(void) const ;
        int get_nz (void) const{}

        void unlink(dll_node_t<T>*);


        int get_size(void) const; // esto: contar los nonzeros
        //modif: suma elementos matriz 

        double suma (void) const; // esto pa arriba


        int get_np (void) const;
        double suma_mat (void) const;
        void invert(void);




        ostream& write(ostream& os) const;
    };

    template<class T> //ATENCION: DE AQUÍ A ABAJO ES LO QUE HECHO YO Y QUE NO ME COMPILA

    void dll_t<T> :: invert(void){

        dll_node_t<T>* aux = get_tail();

        while (aux != NULL){
            dll_t.extract_tail(aux);
            aux = aux -> get_prev();
        }

        while (aux !=NULL){
            dll_t.insert_tail(aux);
            aux=aux->get_next();
        }
    }

MY DOUBT: The errors that I can not understand COMPILING are these:

In member function 'void AED::dll_t<T>::invert()':
64  12      [Error] expected unqualified-id before '.' token
69  9       [Error] expected unqualified-id before '.' token

It is the main, for the new function that I put, I did not change anything there:

#include "dll_pair_t.hpp"

#define N_CHARS 26

using namespace std;
using namespace AED;

int main(void)
{

    dll_pair_t pair_list;
    dll_pair_t pair_list2;  




    node_pair_t* n = NULL;

    n = new node_pair_t(sparse_pair_t(5, 25.0));
    pair_list.insert_tail(n);

    n = new node_pair_t(sparse_pair_t(10, 35.0));
    pair_list.insert_tail(n);

    n = new node_pair_t(sparse_pair_t(25, 45.0));
    pair_list.insert_tail(n);

    // Lista 2

    n = new node_pair_t(sparse_pair_t(200, 1.0));
    pair_list2.insert_tail(n);

    n = new node_pair_t(sparse_pair_t(300, 1.0));
    pair_list2.insert_tail(n);



    dll_rara_pair_t lista_rara;
    node_raro_t* r = NULL;

    r = new node_raro_t(raro_pair_t(1, pair_list));
    lista_rara.insert_tail(r);

    r = new node_raro_t(raro_pair_t(5, pair_list2));
    lista_rara.insert_tail(r);

    lista_rara.write(cout); 

    cout << endl;

    return 0;
}
    
asked by AER 27.07.2017 в 12:56
source

1 answer

3

The error is located in these instructions:

dll_t.extract_tail(aux);
dll_t.insert_tail(aux);

In your case dll_t is the name of the class, surely you wanted to call the functions extract_tail e insert_tail , for this, since you are within a function of your own class ( dll_t::invert ) you do not need to prefix the name of the class:

void dll_t<T> :: invert(void){

    dll_node_t<T>* aux = get_tail();

    while (aux != NULL){
        extract_tail(aux); // <--- sin dll_t.
        aux = aux -> get_prev();
    }

    while (aux !=NULL){
        insert_tail(aux); // <--- sin dll_t.
        aux=aux->get_next();
    }
}

By the way, in

answered by 27.07.2017 / 13:03
source