Results 1 to 3 of 3

Thread: expected type-specifier | not declared in this scope

  1. #1
    Join Date
    Jan 2011
    Posts
    4
    Thanks
    1

    Default expected type-specifier | not declared in this scope

    Hello,
    I work on an old program, there are some errors when I compile it. In member function "void SList<T>::append(T)", errors: expected type-specifier, and errors: "P" was not declared in this scope.

    template<class T>
    class SList {
    public:
    typedef T value_type;
    class Link {
    public:
    value_type _obj;
    Link* _next;
    public:
    Link() { _next = 0; }
    Link(const value_type v, Link* t) : _obj(v), _next(t) { }
    ~Link() {}
    value_type obj() const { return _obj; }
    Link* next() const { return _next; }
    void print() const { cout << obj() << endl; }
    value_type value() const { return obj(); }
    friend class SList;
    friend ostream& operator<< (ostream& os, const Link& t) {
    os << t.obj(); return os;
    }
    };
    class iterator {
    Link* _cur;
    Link* _prev;
    public:
    iterator(): _cur(0), _prev(0)
    {
    }
    iterator& operator= (Link* p)
    {
    _cur = p;
    return *this;
    }
    void set_prev(Link* p)
    {
    _prev = p;
    }
    Link* get_prev()
    {
    return _prev;
    }
    Link* get_cur()
    {
    return _cur;
    }
    Link* operator++()
    {
    assert(_cur != 0);
    return _cur = _cur->_next;
    }
    Link* operator++(int)
    {
    _prev = _cur;
    assert(_cur != 0 );
    _cur = _cur->_next;
    return _prev;
    }
    value_type value()
    {
    assert(_cur != 0 );
    return _cur->value();
    }
    #if 1
    void print() {
    _cur->print();
    };
    #endif
    int operator== (Link* p)
    {
    return _cur == p;
    }
    int operator!= (Link* p)
    {
    return _cur != p;
    }

    };


    void append(const value_type data) {
    Link* a = new SList<value_type>::Link;
    assert( a != 0 );
    a->_obj = data;
    if (_nLinks != 0) {
    a->_next = _last->_next;
    _last = _last->_next = a;
    } else
    _last = a->_next = a;
    _nLinks++;
    }


    int findItem(const value_type val) {
    SList<value_type>::iterator p;
    if ( _nLinks == 0 )
    return 0;
    p = this->begin();
    do {
    if ( p.value() == val )
    return 1;
    } while ( p++ != this->end() );
    return 0;
    }

    Thank you for your kindly help.

  2. #2
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: expected type-specifier | not declared in this scope

    You have to use "typename" keyword.

    Instead of
    Qt Code:
    1. Link* a = new SList<value_type>::Link;
    2. SList<value_type>::iterator p;
    To copy to clipboard, switch view to plain text mode 

    use
    Qt Code:
    1. typename SList<value_type>::Link* a = new typename SList<value_type>::Link;
    2. typename SList<value_type>::iterator p;
    To copy to clipboard, switch view to plain text mode 
    A camel can go 14 days without drink,
    I can't!!!

  3. The following user says thank you to mcosta for this useful post:

    Alain Delon (23rd February 2011)

  4. #3
    Join Date
    Jan 2011
    Posts
    4
    Thanks
    1

    Default Re: expected type-specifier | not declared in this scope

    Thank you very much, you are right!
    The program works well now.
    Thanks again.

Similar Threads

  1. Replies: 12
    Last Post: 28th May 2010, 00:07
  2. `lineEdit' was not declared in this scope?
    By i4ba1 in forum Qt Programming
    Replies: 2
    Last Post: 18th November 2009, 14:36
  3. QDomDocument was not declared in this scope
    By grantbj74 in forum Newbie
    Replies: 5
    Last Post: 25th August 2009, 09:43
  4. glutSolidSphere was not declared in this scope error
    By nuts_fever_007 in forum Qt Programming
    Replies: 2
    Last Post: 15th May 2009, 04:56
  5. Replies: 2
    Last Post: 28th December 2007, 18:30

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.