W
Wally Barnes
Can someone help a poor C++ programmer that learned the language before
there was a standard lib .. etc ?
Basically I have two classes that look something like below:
template <class T>
class ListLogic {
public:
struct LogicBase {
LogicBase () : next(0) { }
LogicBase* next;
};
protected:
LogicBase* head ();
};
template <class T>
class AList : private ListLogic {
protected:
struct ListNode : public ListLogic::LogicBase {
ListNode (const T& d) : data(d) { }
T data;
};
public:
......
T& head () { return ((AList<T>::ListNode*)ListLogic::head())->data; }
};
The 'AList<T>::head()' function is supposed to return the first item in the
list by taking the LogicBase pointer returned by the 'ListLogic::head()'
function and casting it a ListNode struct pointer. Then derefencing it to
retrieve the 'data' part of the ListNode struct.
On earlier versions of g++, this compiles and works fine albeit with the
following warnings:
"warning: `typename AList<T>::ListNode' is implicitly a typename"
"warning: implicit typename is deprecated"
The problem is that on newer versions of g++ the same code now is an error
with the following verbage:
"In member function 'T& AList<T>::head()':"
"error: expected primary-expression before ')' token"
"error: expected `)' before 'ListLogic'"
So it seems the old style casting used previously is no longer allowed. What
is the stardard compliant method of down casting the ListLogic::LogicBase
pointer to the AList<T>::ListNode pointer ? Thanks in advance for any
assistance.
-Wally
there was a standard lib .. etc ?
Basically I have two classes that look something like below:
template <class T>
class ListLogic {
public:
struct LogicBase {
LogicBase () : next(0) { }
LogicBase* next;
};
protected:
LogicBase* head ();
};
template <class T>
class AList : private ListLogic {
protected:
struct ListNode : public ListLogic::LogicBase {
ListNode (const T& d) : data(d) { }
T data;
};
public:
......
T& head () { return ((AList<T>::ListNode*)ListLogic::head())->data; }
};
The 'AList<T>::head()' function is supposed to return the first item in the
list by taking the LogicBase pointer returned by the 'ListLogic::head()'
function and casting it a ListNode struct pointer. Then derefencing it to
retrieve the 'data' part of the ListNode struct.
On earlier versions of g++, this compiles and works fine albeit with the
following warnings:
"warning: `typename AList<T>::ListNode' is implicitly a typename"
"warning: implicit typename is deprecated"
The problem is that on newer versions of g++ the same code now is an error
with the following verbage:
"In member function 'T& AList<T>::head()':"
"error: expected primary-expression before ')' token"
"error: expected `)' before 'ListLogic'"
So it seems the old style casting used previously is no longer allowed. What
is the stardard compliant method of down casting the ListLogic::LogicBase
pointer to the AList<T>::ListNode pointer ? Thanks in advance for any
assistance.
-Wally