home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / cplus / 16563 < prev    next >
Encoding:
Text File  |  1992-11-19  |  1.5 KB  |  45 lines

  1. Path: sparky!uunet!olivea!spool.mu.edu!uwm.edu!ux1.cso.uiuc.edu!news.cso.uiuc.edu!uxa.cso.uiuc.edu!macg9505
  2. From: macg9505@uxa.cso.uiuc.edu (Michael Alan Corn)
  3. Newsgroups: comp.lang.c++
  4. Subject: Help with nested class and constructor
  5. Message-ID: <Bxyxrv.EJ3@news.cso.uiuc.edu>
  6. Date: 19 Nov 92 15:02:17 GMT
  7. Sender: usenet@news.cso.uiuc.edu (Net Noise owner)
  8. Organization: University of Illinois at Urbana
  9. Lines: 34
  10.  
  11.  
  12. I could use a little help on nested classes:
  13.       I would like to include one of Borlands Array classes in another class,
  14. in the private data section, but since the constructor requires an int to
  15. initialize the class, I'm not sure how or where to give it the value:
  16.  
  17. class foo {
  18.       private:
  19.       Array myarray(10); ///this doesn't work, the compiler chokes
  20.  
  21.  
  22. so I've tried this, which seems to work
  23.  
  24. class foo {
  25.       private:
  26.       void *myarray;
  27.  
  28. and then in the constructor for foo I do the following:
  29.  
  30. foo::foo()
  31. {
  32. Array temp(10);
  33. myarray = &temp;
  34.  
  35. Fine, the compiler seems to like this, but now I can't figure out how to
  36. access the member functions of the object I store in myarray.  I use the Array
  37. function ptrAt to get a pointer to the object:
  38.  
  39. myarray->ptrAt(index) and then, since ptrAt returns a Object * I do the
  40. following to get at that objects member function
  41. myarray->ptrAt(index)->memfunc();  This doesn't work.  The compiler complains
  42. about every "->"; I assume that this is a precedence problem, but I really
  43. don't know.  Any help would be greatly appreciated.  Thanks
  44. macg9505@uxa.cso.uiuc.edu
  45.