home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!gatech!destroyer!cs.ubc.ca!unixg.ubc.ca!nistuk
- From: nistuk@unixg.ubc.ca (Richard Nistuk)
- Newsgroups: comp.lang.c++
- Subject: How do I get a smaller array "inside" a bigger array?
- Date: 4 Jan 1993 23:33:43 GMT
- Organization: University of British Columbia, Vancouver, B.C., Canada
- Lines: 45
- Message-ID: <1iahgnINNopg@iskut.ucs.ubc.ca>
- NNTP-Posting-Host: unixg.ubc.ca
- Summary: Help!
-
- Hello,
-
- I'm having a bit of a problem with pointers. What I
- have done is overloaded the "=" and "+" operators to
- return a pointer to a two element array, and I would like
- to place this two element array inside a larger array:
-
- ...
- individual *a,b,c; // create a pointer to an array of
- // "individual" classes and two
- // instances of the "individual"
- // class
-
- a=new individual[4];
-
- b.create(); // initialize b and c
- c.create();
-
- a=b+c; // this works o.k.: a[0] and a[1] hold the
- // solutions of b+c.
-
- ?=c+b; // now how do I get a[2] and a[3] to hold the
- // solutions of c+b?
- ...
-
-
- Is what I want to do possible?
-
- Can I make it work when _a_ has 1000 elements instead
- of 4? For example, assume b,c,and d are instances of
- the class "individual", and a is pointer to an array of
- 1000 "individuals" I would like a[0] and a[1] to be the
- solutions of c+d, say, a[2] and a[3] to the solutions
- of c+d... and a[1998] and a[1999] to be the solutions
- of d+c.
-
- Is what I want to do bad programming style?
- Should I do something else?
-
- BTW, I'm attempting this with TC++.
-
- Thanks in advance for your help.
- --
- Richard Nistuk 4th Yr Physics at U.B.C.
- nistuk@unixg.ubc.ca
-