home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / cplus / 18685 < prev    next >
Encoding:
Internet Message Format  |  1993-01-04  |  1.6 KB

  1. Path: sparky!uunet!gatech!destroyer!cs.ubc.ca!unixg.ubc.ca!nistuk
  2. From: nistuk@unixg.ubc.ca (Richard Nistuk)
  3. Newsgroups: comp.lang.c++
  4. Subject: How do I get a smaller array "inside" a bigger array?
  5. Date: 4 Jan 1993 23:33:43 GMT
  6. Organization: University of British Columbia, Vancouver, B.C., Canada
  7. Lines: 45
  8. Message-ID: <1iahgnINNopg@iskut.ucs.ubc.ca>
  9. NNTP-Posting-Host: unixg.ubc.ca
  10. Summary: Help!
  11.  
  12. Hello,
  13.  
  14.   I'm having a bit of a problem with pointers.  What I
  15. have done is overloaded the "=" and "+" operators to
  16. return a pointer to a two element array, and I would like
  17. to place this two element array inside a larger array:
  18.  
  19. ...
  20. individual *a,b,c; // create a pointer to an array of
  21.                    // "individual" classes and two 
  22.                    // instances of the "individual"
  23.                    // class 
  24.  
  25. a=new individual[4];
  26.  
  27. b.create();     // initialize b and c
  28. c.create();
  29.  
  30. a=b+c; // this works o.k.: a[0] and a[1] hold the
  31.        // solutions of b+c.
  32.  
  33. ?=c+b; // now how do I get a[2] and a[3] to hold the
  34.        // solutions of c+b?
  35. ...
  36.  
  37.  
  38. Is what I want to do possible?
  39.   
  40. Can I make it work when _a_ has 1000 elements instead
  41. of 4?  For example, assume b,c,and d are instances of
  42. the class "individual", and a is pointer to an array of
  43. 1000 "individuals" I would like a[0] and a[1] to be the
  44. solutions of c+d, say, a[2] and a[3] to the solutions
  45. of c+d... and a[1998] and a[1999] to be the solutions
  46. of d+c.
  47.  
  48. Is what I want to do bad programming style?  
  49. Should I do something else?
  50.  
  51. BTW, I'm attempting this with TC++.  
  52.  
  53. Thanks in advance for your help.
  54. -- 
  55. Richard Nistuk               4th Yr Physics at U.B.C.
  56. nistuk@unixg.ubc.ca
  57.