CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Template Error

  1. #1
    Join Date
    Feb 2003
    Location
    Germany
    Posts
    89

    Template Error

    Hi,

    I was trying to use this tracer I found on Codeexpert. On compiling, I get the following error:


    Code:
     
    template <class T>
    class SS_List
    {
    public:
    
        // construction, destruction
        SS_List();
        virtual ~SS_List();
    
        // copy and assignment
        SS_List(SS_List& rhs) { InitObject(); *this = rhs; }
        SS_List& operator = (SS_List& rhs)
        {
            RemoveAll();
            InitObject(); 
            Iterator it = rhs.Beginning();
            while( it.IsValid() )
            {
                InsertEnd(it.Current());
                ++it;
            }        
            return *this;
        }
    
        // Helper sub-class
        class Object
        {
        public:
            Object() { m_pNext = NULL; m_pPrev = NULL; }
            ~Object() {}
    
            T        m_Value;
    
            Object*  m_pNext;
            Object*  m_pPrev;
        };
        
        class Iterator
        {
        public:
    
            Iterator() { InitObject(&Object()); }
            Iterator(Object* pObject) { InitObject(pObject); }
            
            VOID InitObject(Object* pObject) { m_pCurrent = pObject; }        
            VOID operator = (Object* pObject) { InitObject(pObject); }
    
            T& operator ++ () 
            { 
                if( m_pCurrent->m_pNext )
                    InitObject(m_pCurrent->m_pNext);
                else
                    InitObject(NULL);
    
                return Current();
            }
    
            T& operator -- ()
            { 
                if( m_pCurrent->m_pPrev )
                    InitObject(m_pCurrent->m_pPrev);
                else
                    InitObject(NULL);
                
                return Current();
            }
    
            BOOL operator != (Object* rhs) { return m_pCurrent != rhs ? TRUE : FALSE; }
            BOOL operator == (Object* rhs) { return m_pCurrent == rhs ? TRUE : FALSE; }
            
            T& operator -> () { return Current(); }
    		operator T () { return Current(); }
            
            T& Current() { return m_pCurrent->m_Value; }
            T& Next() { ++(*this); return Current(); }
            T& Prev() { --(*this); return Current(); }
    
            BOOL IsLast() { return (m_pCurrent->m_pNext == NULL) ? TRUE : FALSE; }
            BOOL IsFirst() { return (m_pCurrent->m_pPrev == NULL) ? TRUE : FALSE; }
            BOOL IsValid() { return (m_pCurrent != NULL) ? TRUE : FALSE; }
            
        private:
    
            Object* m_pCurrent;
    
        };
        
    protected:
    
        // initialization
        virtual VOID	            InitObject		        ();
    
    public:
    
    	// accessor functions
        Object*                     Beginning               ();
        Object*                     End                     ();
        
        // utilities
        VOID                        InsertBeginning         (T object);
        VOID                        InsertEnd               (T object);
        VOID                        Insert                  (T object, INT nIndex);
        VOID                        Remove                  (INT nIndex);
        VOID                        RemoveAll               ();
        BOOL                        RemoveCurrent           (Iterator& it);
        
        INT                         Count                   ();
        INT                         IncrementCount          ();
        INT                         DecrementCount          ();
    
        T&                          GetAt                   (INT nIndex);
        T&                          operator []             (INT nIndex);
        
    protected:
    
        VOID                        Beginning               (Object* pObject);
        VOID                        End                     (Object* pObject);
        VOID                        Count                   (INT nCount);
        Object*                     GetObjectAt             (INT nIndex);
        
    private:
    
        Object*                     m_pBegin;
        Object*                     m_pEnd;
        INT                         m_nCount;
    
    };
    
    // ----------------------------------------------------------------------- //
    //  SS_List Accessor Functions
    // ----------------------------------------------------------------------- //
    
    template <class T>
    inline SS_List<T>::Object* SS_List<T>::Beginning()   // this is line #171
    { return m_pBegin; }
    I get the following error:
    Code:
    d:\c++\log fast\ss_log_src\ss_list.h(171) : error C2143: Syntaxfehler: Es fehlt ';' vor '*'
    This seems to be a VS7 / VS9 porting problem; but I'm not familiar with Templates, so could anybody please tell me what's wrong here?

    Thanx a lot in adv.
    Last edited by Wild Thing; July 26th, 2008 at 05:31 PM.
    prepare that the light at the end of your tunnel is just a freight train coming your way - metallica

  2. #2
    Join Date
    Jan 2002
    Location
    Scaro, UK
    Posts
    5,940

    Re: Template Error

    Much as I love fixing errors in code which was posted on other sites (and did you contact the authors of the code) I'm feeling generous...

    This should fix your issue.

    Code:
    template <class T>
    inline typename SS_List<T>::Object* SS_List<T>::Beginning()
    { return m_pBegin; }
    Notice the 'typename' addition.

    And why ? Because the compiler needs to know if SS_List<T>::Object is a static member variable or a type.

    Darwen.
    www.pinvoker.com - PInvoker - the .NET PInvoke Interface Exporter for C++ Dlls.

  3. #3
    Join Date
    May 2007
    Posts
    811

    Re: Template Error

    I just can't resist:

    Wild Thing Location: Germany
    Code:
    template <class T>
    class SS_List;
    No offense intended.

  4. #4
    Join Date
    Sep 2004
    Location
    Holland (land of the dope)
    Posts
    4,123

    Talking Re: Template Error

    hahahaha

  5. #5
    Join Date
    Feb 2003
    Location
    Germany
    Posts
    89

    Re: Template Error

    Quote Originally Posted by darwen
    Much as I love fixing errors in code which was posted on other sites (and did you contact the authors of the code) I'm feeling generous...
    Thanks a lot, Darwen; I am still learning...

    (Sorry for the "other side", but at least I didn' pretend it to be my own..)

    @STLDude:
    now that you mention it....
    prepare that the light at the end of your tunnel is just a freight train coming your way - metallica

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured