-
July 26th, 2008, 05:26 PM
#1
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
-
July 26th, 2008, 06:51 PM
#2
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.
-
July 26th, 2008, 07:00 PM
#3
Re: Template Error
I just can't resist:
Wild Thing Location: Germany
Code:
template <class T>
class SS_List;
No offense intended.
-
July 26th, 2008, 07:05 PM
#4
Re: Template Error
hahahaha
-
July 27th, 2008, 12:46 AM
#5
Re: Template Error
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|