Thread: cant solve this error

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    11

    cant solve this error

    hi all , I have writen a set.h file ! but I keep receiving these errors :

    Set.h: In member function ‘void Set<T>::add(const T&)’:
    Set.h:29: error: expected ‘;’ before ‘result’
    Set.h:33: error: ‘result’ was not declared in this scope
    Set.h: In member function ‘void Set<T>::remove(const T&)’:
    Set.h:55: error: expected ‘;’ before ‘it’
    Set.h:57: error: ‘it’ was not declared in this scope
    Set.h: In member function ‘bool Set<T>::exists(const T&) const’:
    Set.h:83: error: expected ‘;’ before ‘result’
    Set.h:85: error: ‘result’ was not declared in this scope

    can anybody help me solve it?

    my code is :

    Code:
    //Jeren AKHOUNDI (1836345) Homework2 set.h
    
    
    #ifndef __SET_H__
    #define __SET_H__
    
    using namespace std;
    #include <iostream>
    #include <vector>
    #include <algorithm>
    #include "SetException.h"
    
    
    template <class T> class Set
    {
    
    private:
    
    vector<T> v;
    
    
    public:
    
    // ADD ==================================================================================
    void add (const T& x)
        { 
    
        
        vector<T>::iterator result;
        
        //try
        //{
            result = find (v.begin(), v.end(), x);
            if (result != v.end())
                {
                throw SetException(ITEM_ALREADY_EXISTS,"item already exists");
                }
        //}
        //catch (SetException& exc)
            //{
            //exc.what();
            //}
        
    
        v.push_back(x);
    
        }
    
    
    
    // REMOVE ===============================================================================
    void remove (const T& x)
        { 
    
        vector<T>::iterator it;
            
        it = search (v.begin(), v.end(), x);
    
        //try
        //{
        if (it == v.end())
            throw SetException(ITEM_NOT_EXISTS,"item not exists");
        
    
        //catch (SetException& exc)
            //{
            //exc.what();
            //}
        
        
        else
            {
            int def = it - v.begin();
            v.erase(v.begin() + def );
            }
    
    
        }
    
    // EXISTS  ===============================================================================
    bool exists(const T& item)const
        {
        vector<T>::iterator result;
        
        result = find (v.begin() , v.end(), item);
        if (result != v.end)
            return true;
        else
            return false;
        }
    
    
    // CARDINALITY ===========================================================================
    int cardinality()const
        {
        return v.size();
    
        //int result;
        //for (int i=0; i<v.end(); i++)
            //{
            //result = v.count(i);
            //}
        //return result;
        }
            
    
    
    }; // end of class
    
    
    
    #endif

  2. #2
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    Your compiler sucks at giving error messages ... mine wins !!
    As "vector<T>::iterator" is apparently a dependant scope... you'd need a 'typename' before those statements.



    Btw... from your code in the earlier thread, it is almost clear that this isn't your work.
    (If it is... and you somehow managed to learn so much in so little time...then congrats.)
    Last edited by manasij7479; 11-27-2011 at 01:10 PM.

  3. #3
    Registered User
    Join Date
    Nov 2011
    Posts
    11
    thanks for the answer

    I didnt get what I should do ! can you tell me where to change?

  4. #4
    Registered User
    Join Date
    Nov 2011
    Posts
    11
    and what can be wrong with my compiler? I am using gcc for ubuntu ! any suggestion?

  5. #5
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    Quote Originally Posted by Jeren View Post
    and what can be wrong with my compiler? I am using gcc for ubuntu ! any suggestion?
    gcc version ?

  6. #6
    Registered User
    Join Date
    Nov 2011
    Posts
    11
    gcc 4.4

  7. #7
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    #1.
    Code:
    using namespace std;
    #include <iostream>
    #include <vector>
    #include <algorithm>
    #include "SetException.h"
    Avoid putting a using namespace declaration in your header files.

    #2
    Code:
    #ifndef __SET_H__
    #define __SET_H__
    Your identifier __SET_H__ runs afoul of the rules:
    Use of two sequential underscore characters ( __ ) at the beginning of an identifier, or a single leading underscore followed by a capital letter, is reserved for C++ implementations in all scopes. You should avoid using one leading underscore followed by a lowercase letter for names with file scope because of possible conflicts with current or future reserved identifiers.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. solve this error
    By moussa in forum C Programming
    Replies: 3
    Last Post: 05-28-2008, 05:38 AM
  2. how to solve this error msg
    By rhythm in forum C++ Programming
    Replies: 11
    Last Post: 02-08-2008, 10:05 PM
  3. error cant solve
    By developer47 in forum C Programming
    Replies: 1
    Last Post: 04-30-2007, 05:10 AM
  4. Cant solve this error... please help...
    By Goosie in forum C++ Programming
    Replies: 16
    Last Post: 07-08-2005, 10:32 PM
  5. ^^ help me solve the error
    By skwei81 in forum C++ Programming
    Replies: 2
    Last Post: 04-03-2003, 09:04 AM