Results 1 to 4 of 4

Thread: Need Help =(

  1. #1

    Need Help =(

    I really cant seem to make this compile correctly with red hat and what the compiler says its wrong its weird
    anyways any help??

    #include <iostream>
    #include <cstdlib>
    #include <cassert>
    #include "CLList.h"

    namespace uprm_icom4035 {

    //////////////// DO NOT MODIFY THESE FUNCTIONS //////////////////////////////
    template <typename Item>
    void CLList<Item>:rint_list(ostream& out) const{
    cl_list_node<Item> *temp = NULL;

    // print each data value on a separate line
    for (temp = header->next; temp != header; temp = temp->next){
    out << temp->data << endl;
    }
    }


    // Return the element at the current location of the iterator
    // Note: This function will throw a string exception if the
    // Iterator is not on a valid node with data (i.e. the header)
    template <typename Item>
    Item& CLLIterator<Item>::get_data() const {
    if (has_data()){
    return curr->data;
    }
    else {
    string msg = "CLLIterator<Item>::get_data()Error: Iterator has no data to return.";
    throw msg;
    }
    }

    // Constructor for the iterator
    template <typename Item>
    CLLIterator<Item>::CLLIterator(cl_list_node<Item>* hdr,
    cl_list_node<Item>* tail):Iterator<Item>(){
    this->hdr = hdr;
    this->tail = tail;
    this->curr = hdr;
    }


    //////////////////////////////////////////////////////////////////////////

    /************* START ADDING FOR CODE FROM HERE **************************/




    /////********IMPLEMENTACION DEL ITERADOR DE LA LISTA REDONDA**********///////////
    //ARREGLO bien pues no chekea bien si esta vacio no hay tail aki
    template<typename Item>
    bool CLLIterator<Item>::has_data()const{
    return this->curr!=header;
    //return (this->hdr == header && this->curr==header && this->tail==header);
    }


    //SUPER IMP AKI QUE SI SIGUE HACIA ALFRENTE
    template<typename Item>
    void CLLIterator<Item>::next(){
    if(curr->next != header)
    curr = curr->next;
    }

    template<typename Item>
    void CLLIterator<Item>::reset(){
    curr = hdr;
    }


    template<typename Item>
    void CLLIterator<Item>:rev(){
    if(curr->prev!=header)
    curr = curr->prev;
    }


    //*************COMIENZA IMPLEMENTACION DE CLLIST*****************//

    //Constructor de la lista
    template<typename Item>
    CLList<Item>::CLList(){
    header = new cl_list_node<Item>();
    header->next = header;
    header->prev=header;
    }


    //COpy constructor
    //CHEKEAR
    template<typename Item>
    CLList<Item>::CLList(const CLList<Item>& L){
    for(CLLIterator<Item>* iter = L.first(); iter.has_data(); iter->next()){
    this->insert(iter->get_data());}
    }


    template<typename Item>
    CLList<Item>::~CLList(){
    this->make_empty();
    delete header;
    header = NULL;
    }


    //OPERATOR = usa el codigo de el copy pero devuelve el this
    template<typename Item>
    const CLList<Item>& CLList<Item>:perator=(const CLList<Item>& L){
    if(this==&L){
    return *this;
    }
    else{
    this->make_empty();
    for(CLLIterator<Item>* iter = L.first(); iter.has_data(); iter->next()){
    this->insert(iter->get_data());}
    return *this;
    }
    }


    //Funcion de FIND
    template<typename Item>
    Iterator<Item>* CLList<Item>::find(const Item& obj) const{
    cl_list_node<Item>* temp = NULL;
    for(temp = header->next; temp != header; temp = temp->next){
    if(temp->data==obj){
    return new CLLIterator<Item>(temp);
    }
    }
    return NULL;
    }

    //Funcion de first devuelve iterador al primer elemento
    template<typename Item>
    Iterator<Item>* CLList<Item>::first() const{
    CLLIterator<Item>* temp = new CLLIterator<Item>(header->next);
    return temp;
    }

    template<typename Item>
    void CLList<Item>::insert(const Item& obj){
    cl_list_node<Item>* temp=NULL, *temp2=NULL;
    temp = new cl_list_node<Item>;
    if(this->is_empty()){
    temp->data=obj;
    header->next = temp;
    temp->prev = header;
    temp->next = header;
    header->prev = temp;
    }
    else{
    for(temp2=header->next; temp2!= header; temp2 = temp2->next){
    if(temp2->data < obj || temp2->next=header){
    temp->data = obj;
    temp->next = temp2->next;
    temp->prev = temp2;
    temp2->next->prev = temp;
    temp2->next = temp;
    return;
    }
    }
    }
    }
    //Funcion de borrar un elemento
    template<typename Item>
    bool CLList<Item>::erase(const Item& obj){
    cl_list_node<Item>* temp=NULL, *temp2=NULL;
    if(this->is_empty())
    return false;
    else{
    for(temp2=header->next; temp2!=header; temp2=temp2->next){
    if(temp2->data = obj){
    temp2->prev->next=temp2->next;
    temp2->next->prev = temp2->prev;
    delete temp2;
    return true;
    }
    }
    }
    return false;
    }

    template<typename Item>
    CLList::size_type CLList<Item>::size() const{
    size_type amount = 0;

    for(cl_list_node<Item>* temp = header->next; temp != header; temp=temp->next){
    ++amount;
    }
    return amount;
    }
    template<typename Item>
    bool CLList<Item>::is_empty() const{
    return header->next==header;
    }

    template<typename Item>
    void CLList<Item>::make_empty(){
    while(!is_empty()){
    erase(header->next->data);}
    }

    }








    ERRORS::
    g++ -g -Wall -c CLList.cpp
    In file included from CLList.h:4,
    from CLList.cpp:4:
    list.h:14: warning: `typename uprm_icom4035::Iterator<Item>::value_type' is
    implicitly a typename
    list.h:14: warning: implicit typename is deprecated, please see the
    documentation for details
    In file included from CLList.cpp:4:
    CLList.h:50: warning: `typename uprm_icom4035::CLList<Item>::size_type' is
    implicitly a typename
    CLList.h:50: warning: implicit typename is deprecated, please see the
    documentation for details
    CLList.cpp:186: syntax error before `::' token
    CLList.cpp:186: syntax error before `<' token
    CLList.cpp:189: syntax error before `!=' token
    CLList.cpp:189: ISO C++ forbids declaration of `temp' with no type
    CLList.cpp:189: `temp' was not declared in this scope
    CLList.cpp:189: parse error before `)' token
    CLList.cpp:195: syntax error before `::' token
    CLList.cpp:195: ISO C++ forbids declaration of `is_empty' with no type
    CLList.cpp:195: non-member function `int is_empty()' cannot have `const' method
    qualifier
    CLList.cpp: In function `int is_empty()':
    CLList.cpp:196: `header' undeclared (first use this function)
    CLList.cpp:196: (Each undeclared identifier is reported only once for each
    function it appears in.)
    CLList.cpp: At global scope:
    CLList.cpp:200: syntax error before `::' token
    CLList.cpp:200: ISO C++ forbids declaration of `make_empty' with no type
    CLList.cpp: In function `int make_empty()':
    CLList.cpp:202: `erase' undeclared (first use this function)
    CLList.cpp: At global scope:
    CLList.cpp:205: parse error before `}' token
    I Speak in frequencies even dogs have trouble hearing


  2. #2
    Elite Hacker
    Join Date
    Mar 2003
    Posts
    1,407
    Maybe the errors are from the smilies in your code. Click edit on your post and check the box to disable the smilies. I hope you get a real answer to your question, but I don't know c++. You may also want to look into the code tags.
    ["code"]
    code here
    ["/code"]
    without the quotes of course. Good luck.

  3. #3
    Senior Member
    Join Date
    Jul 2003
    Posts
    114
    Here's the code, reformatted to look okay. I don't know C++, but there is apparently a syntax error on line 186, which is:
    Code:
    CLList::size_type CLList<Item>::size() const {
    Anyway, here's the code properly formatted code. Sorry about the long lines:
    Code:
    #include <iostream> 
    #include <cstdlib> 
    #include <cassert> 
    #include "CLList.h" 
    
    namespace uprm_icom4035 { 
    
        //////////////// DO NOT MODIFY THESE FUNCTIONS ////////////////////////////// 
        template <typename Item> 
        void CLList<Item>::-Print_list(ostream& out) const { 
            cl_list_node<Item> *temp = NULL; 
    
            // print each data value on a separate line 
            for (temp = header->next; temp != header; temp = temp->next) { 
                out << temp->data << endl; 
            }
        }
    
    
        // Return the element at the current location of the iterator 
        // Note: This function will throw a string exception if the 
        // Iterator is not on a valid node with data (i.e. the header) 
        template <typename Item> 
        Item& CLLIterator<Item>::get_data() const { 
            if (has_data()){ 
                return curr->data; 
            }
            else { 
                string msg = "CLLIterator<Item>::get_data()Error: Iterator has no data to return."; 
                throw msg; 
            }
        }
    
        // Constructor for the iterator 
        template <typename Item> 
        CLLIterator<Item>::CLLIterator(cl_list_node<Item>* hdr, cl_list_node<Item>* tail):Iterator<Item>() { 
            this->hdr = hdr; 
            this->tail = tail; 
            this->curr = hdr; 
        }
    
    
        ////////////////////////////////////////////////////////////////////////// 
    
        /************* START ADDING FOR CODE FROM HERE **************************/ 
    
    
    
        /////********IMPLEMENTACION DEL ITERADOR DE LA LISTA REDONDA**********/////////// 
        //ARREGLO bien pues no chekea bien si esta vacio no hay tail aki 
        template<typename Item> 
        bool CLLIterator<Item>::has_data()const{ 
            return this->curr!=header; 
            //return (this->hdr == header && this->curr==header && this->tail==header); 
        }
    
    
        //SUPER IMP AKI QUE SI SIGUE HACIA ALFRENTE 
        template<typename Item> 
        void CLLIterator<Item>::next(){ 
            if(curr->next != header) 
                curr = curr->next; 
        }
    
        template<typename Item> 
        void CLLIterator<Item>::reset(){ 
            curr = hdr; 
        }
    
    
        template<typename Item> 
        void CLLIterator<Item>: rev(){ 
            if(curr->prev!=header) 
                curr = curr->prev; 
        }
    
    
        //*************COMIENZA IMPLEMENTACION DE CLLIST*****************// 
    
        //Constructor de la lista 
        template<typename Item> 
        CLList<Item>::CLList(){ 
            header = new cl_list_node<Item>(); 
            header->next = header; 
            header->prev=header; 
        }
    
    
        //COpy constructor 
        //CHEKEAR 
        template<typename Item> 
        CLList<Item>::CLList(const CLList<Item>& L){ 
            for(CLLIterator<Item>* iter = L.first(); iter.has_data(); iter->next()){ 
                this->insert(iter->get_data());} 
        }
    
    
        template<typename Item> 
        CLList<Item>::~CLList(){ 
            this->make_empty(); 
            delete header; 
            header = NULL; 
        }
    
    
        //OPERATOR = usa el codigo de el copy pero devuelve el this 
        template<typename Item> 
        const CLList<Item>& CLList<Item>: perator=(const CLList<Item>& L) { 
            if(this==&L) { 
                return *this; 
            }
            else { 
                this->make_empty(); 
                for(CLLIterator<Item>* iter = L.first(); iter.has_data(); iter->next()) { 
                    this->insert(iter->get_data());
                } 
                return *this; 
            }
        }
    
    
        //Funcion de FIND 
        template<typename Item> 
        Iterator<Item>* CLList<Item>::find(const Item& obj) const{ 
            cl_list_node<Item>* temp = NULL; 
            for(temp = header->next; temp != header; temp = temp->next){ 
                if(temp->data==obj) { 
                    return new CLLIterator<Item>(temp); 
                }
            }
            return NULL; 
        }
    
        //Funcion de first devuelve iterador al primer elemento 
        template<typename Item> 
        Iterator<Item>* CLList<Item>::first() const { 
            CLLIterator<Item>* temp = new CLLIterator<Item>(header->next); 
            return temp; 
        }
    
        template<typename Item> 
        void CLList<Item>::insert(const Item& obj) { 
            cl_list_node<Item>* temp=NULL, *temp2=NULL; 
            temp = new cl_list_node<Item>; 
            if(this->is_empty()){ 
                temp->data=obj; 
                header->next = temp; 
                temp->prev = header; 
                temp->next = header; 
                header->prev = temp; 
            }
            else{ 
                for(temp2=header->next; temp2!= header; temp2 = temp2->next) { 
                    if(temp2->data < obj || temp2->next=header) { 
                        temp->data = obj; 
                        temp->next = temp2->next; 
                        temp->prev = temp2; 
                        temp2->next->prev = temp; 
                        temp2->next = temp; 
                        return; 
                    }
                }
            }
        }
        //Funcion de borrar un elemento 
        template<typename Item> 
        bool CLList<Item>::erase(const Item& obj) { 
            cl_list_node<Item>* temp=NULL, *temp2=NULL; 
            if(this->is_empty()) {
                return false; 
            }
            else { 
                for(temp2=header->next; temp2!=header; temp2=temp2->next) { 
                    if(temp2->data = obj) { 
                        temp2->prev->next=temp2->next; 
                        temp2->next->prev = temp2->prev; 
                        delete temp2; 
                        return true; 
                    }
                }
            }
            return false; 
        }
    
        template<typename Item> 
        CLList::size_type CLList<Item>::size() const { 
            size_type amount = 0; 
    
            for(cl_list_node<Item>* temp = header->next; temp != header; temp=temp->next) { 
                ++amount; 
            }
            return amount; 
        }
        template<typename Item> 
        bool CLList<Item>::is_empty() const { 
            return header->next==header; 
        }
    
        template<typename Item> 
        void CLList<Item>::make_empty() { 
            while(!is_empty()) { 
                erase(header->next->data);
            } 
        }
    
    }

  4. #4
    Senior Member
    Join Date
    May 2002
    Posts
    344
    i personally think that the errors make perfect sense...i havent fully looked through your code and understood all of it, but your error report sounds like you made little errors here and there. if there is an error you dont understand, then just click on it and then click F1 and normally a little help window will pop up and will explain to you what the error is and sometimes how to fix it. Also, the comments in spanish dont help me understand the code you might want to change them to enlish porque mi espanol es muy malo
    Support your right to arm bears.


    ^^This was the first video game which i played on an old win3.1 box

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •