home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / cplus / 16649 < prev    next >
Encoding:
Internet Message Format  |  1992-11-20  |  1.6 KB

  1. Path: sparky!uunet!mcsun!uknet!glasgow!unix.brighton.ac.uk!je
  2. From: je@unix.brighton.ac.uk (John English)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Help with nested class and constructor
  5. Message-ID: <1992Nov20.154512.22771@unix.brighton.ac.uk>
  6. Date: 20 Nov 92 15:45:12 GMT
  7. References: <Bxyxrv.EJ3@news.cso.uiuc.edu>
  8. Organization: University of Brighton, UK
  9. Lines: 28
  10.  
  11. macg9505@uxa.cso.uiuc.edu (Michael Alan Corn) writes:
  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. : class foo {
  17. :       private:
  18. :       Array myarray(10); ///this doesn't work, the compiler chokes
  19.               ^^^^^^^^^^^
  20.           This is a constructor call to Array, not allowed here.
  21. That's why the compiler chokes.  What you need is:
  22.  
  23.      Array myarray;
  24.  
  25. in the class declaration, and in the constructor do this:
  26.  
  27.     foo::foo () : myarray (10) { } // Array constructor for myarray
  28.                    // gets called at foo construct time.
  29. -- 
  30. -------------------------------------------------------------------------------
  31. John English            | "Yes, understanding today's complex world of
  32. Dept. of Computing        |  the future IS a little like having bees live
  33. University of Brighton        |  in your head... but, there they are..."
  34. Janet: je @ unix.brighton.ac.uk    | "People who live in windowed environments
  35. Fax:   0273 642405        |  shouldn't cast pointers"
  36. -------------------------------------------------------------------------------
  37.