home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!olivea!spool.mu.edu!uwm.edu!ux1.cso.uiuc.edu!news.cso.uiuc.edu!uxa.cso.uiuc.edu!macg9505
- From: macg9505@uxa.cso.uiuc.edu (Michael Alan Corn)
- Newsgroups: comp.lang.c++
- Subject: Help with nested class and constructor
- Message-ID: <Bxyxrv.EJ3@news.cso.uiuc.edu>
- Date: 19 Nov 92 15:02:17 GMT
- Sender: usenet@news.cso.uiuc.edu (Net Noise owner)
- Organization: University of Illinois at Urbana
- Lines: 34
-
-
- I could use a little help on nested classes:
- I would like to include one of Borlands Array classes in another class,
- in the private data section, but since the constructor requires an int to
- initialize the class, I'm not sure how or where to give it the value:
-
- class foo {
- private:
- Array myarray(10); ///this doesn't work, the compiler chokes
-
-
- so I've tried this, which seems to work
-
- class foo {
- private:
- void *myarray;
-
- and then in the constructor for foo I do the following:
-
- foo::foo()
- {
- Array temp(10);
- myarray = &temp;
-
- Fine, the compiler seems to like this, but now I can't figure out how to
- access the member functions of the object I store in myarray. I use the Array
- function ptrAt to get a pointer to the object:
-
- myarray->ptrAt(index) and then, since ptrAt returns a Object * I do the
- following to get at that objects member function
- myarray->ptrAt(index)->memfunc(); This doesn't work. The compiler complains
- about every "->"; I assume that this is a precedence problem, but I really
- don't know. Any help would be greatly appreciated. Thanks
- macg9505@uxa.cso.uiuc.edu
-