I am teaching myself C++ %26amp; data structures these days, and now I encountered a UNBELIEVABLE setback!
I have been busy solving it right now and I feel exhausted.
Please take your time and check my code, it's an unbelieve error.
"class List" is inherited from base class "ablist".
I wondered why accessing "pHead""length" etc; is forbidden in class list, even they are inherited from "ablist"?
I hve to use "ablist %26lt;type%26gt;::pHead" to access to pHead.
//*************************//
//ListNode
//*************************//
template %26lt;class type%26gt;
class ListNode
{
public:
ListNode();
type data;
ListNode %26lt;type%26gt;* pNext;
};
//Fuction(){codes..}..
//*************************//
//ablist
//*************************//
template %26lt;class type%26gt;
class ablist
{
public:
ListNode %26lt;type%26gt; *pHead;
ListNode %26lt;type%26gt; *pCurrent;
ListNode %26lt;type%26gt; *pTail;
int length;
//Fuction(){codes..}..
};
//Fuction(){codes..}..
//***********
ERROR,C++,data structures,teaching myself,setback?
I'm not sure why you need your List class as defined, but you could write List%26lt;type%26gt;::pHead instead of ablist%26lt;type%26gt;::pHead in your List class operations, if you prefer. Trying to reference pHead by itself isn't valid, since it's defined in terms of %26lt;type%26gt;.
It seems like you could do away with your List class, and instantiate whatever kinds of ablist classes you need. E.g.:
typedef ablist%26lt;int%26gt; IntListInst;
class IntList : public IntListInst
{
// ... implementation of ablist operations
};
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment