home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / cplus / 17914 < prev    next >
Encoding:
Internet Message Format  |  1992-12-14  |  1.3 KB

  1. Path: sparky!uunet!mcsun!julienas!loria!loria.fr!eker
  2. From: eker@loria.fr (Steven Eker)
  3. Newsgroups: comp.lang.c++
  4. Subject: classes within templates
  5. Message-ID: <691@muller.loria.fr>
  6. Date: 14 Dec 92 12:08:42 GMT
  7. Sender: news@news.loria.fr
  8. Organization: CRIN (CNRS) Nancy - INRIA Lorraine
  9. Lines: 39
  10.  
  11. What is the semantics of nesting classes within a template class?
  12. I want to implement a template container class where the internal structs are
  13. hidden:
  14.  
  15. template<class T> class My_container {
  16.  
  17.   struct internal_stuff {
  18.     internal_stuff* link;
  19.     T data;
  20.     ...
  21.   };
  22.  
  23.   internal_stuff* ptr1;
  24.   ...
  25. };
  26.  
  27. This seems to work ok until I want to have an friend class for iterators
  28. (assume "friend class My_iter<T>;" included in above def):
  29.  
  30. template<class T> class My_iter {
  31.  
  32.   internal_stuff* ptr2;
  33.   ...
  34. };
  35.  
  36. At this point the compiler (gcc v2.1) complains of a syntax error
  37. before '*' and bombs.
  38.  
  39. What is the status of "internal_stuff"? Is it implicitly parameterised
  40. by T? Does it make sense to declare a template within a template
  41. (a) with parameters that are a subset of enclosing templete parameters
  42. (b) with parameters that don't exist in enclosing template?
  43.  
  44. What's the best way to hide the internal classes/structs of a complicated
  45. container class from global name space?
  46.  
  47. tia
  48.  
  49. Steven            eker@loria.fr
  50.