By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,797 Members | 1,848 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,797 IT Pros & Developers. It's quick & easy.

AIX va7 "template dependent name that is not a type must be qualified" warning

P: 1
On AIX, a template class containing a nested class which needs to be a friend provokes a warning:

(W) A template dependent name that is a type must be qualified with "typename".

and method definitons give this warning:

(S) The class qualifier "List" contains a circular reference back to ""

How can these be avoided?

Following is a complete demo program, which g++ 4.1.1 accepts without complaint.

Thanks to anyone who can help!
Expand|Select|Wrap|Line Numbers
  1. template <class T>
  2. class List {
  3. public:
  4.     List() : m_Head(0) {};
  5.     void Prepend(T item);
  6.  
  7.     // 1540-0152 (W) A template dependent name that 
  8.     // is a type must be qualified with "typename".
  9.     class Iter;
  10.     friend class List<T>::Iter;  // <-- WARNING HERE
  11.  
  12.     //Does not work: friend class List<typename T>::Iter;
  13.     //Does not work: friend typename class List<T>::Iter;
  14.     //Does not work: friend class typename List<T>::Iter;
  15.  
  16.     class Iter {
  17.     public:
  18.       Iter(const List & list);
  19.       bool Done(void);
  20.       T GetCurrent(void);
  21.       void Advance(void);
  22.     private:
  23.       typename List<T>::Link * m_Curr;
  24.     };
  25. private:
  26.     struct Link {
  27.       T value;
  28.       Link *next;
  29.     };
  30.     Link * m_Head;
  31. };
  32.  
  33. // 1540-0100 (S) The class qualifier "List" contains a circular reference back to "".
  34. template <class T> void List<T>::Prepend(T item) { // <--WARNING HERE
  35.   Link *newlink = new Link;
  36.   newlink->value = item;
  37.   if (m_Head == 0) {
  38.     newlink->next = 0;
  39.     m_Head = newlink;
  40.   } else {
  41.     newlink->next = m_Head;
  42.     m_Head = newlink;
  43.   }
  44. };
  45. template<class T> List<T>::Iter::Iter(const List<T> & list)
  46.   : m_Curr(list.m_Head)
  47. { }
  48. template<class T> bool List<T>::Iter::Done(void) { return (m_Curr==0); }
  49. template<class T> T List<T>::Iter::GetCurrent(void) { return m_Curr->value; }
  50. template<class T> void List<T>::Iter::Advance(void) {
  51.   if (m_Curr != 0) { m_Curr = m_Curr->next; }
  52. }
  53.  
  54. #include <iostream>
  55. using namespace std;
  56. int main() {
  57.   typedef List<int> ListOfInt_t;
  58.   ListOfInt_t list;
  59.  
  60.   for (int i=0; i<10; ++i) { list.Prepend(i); }
  61.  
  62.   for (ListOfInt_t::Iter iter(list);
  63.        ! iter.Done();
  64.        iter.Advance())
  65.   {
  66.    cout << "Item: " << iter.GetCurrent() << endl;
  67.   }
  68.  
  69.   return 0;
  70. }
  71.  
Mar 16 '07 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.