Message-ID: <3373626C.70F7@mailbox.swipnet.se> Date: Tue, 13 May 1997 22:44:12 -2000 From: Krystyna de Heras MIME-Version: 1.0 To: djgpp AT delorie DOT com Subject: Re: HELP! Pointers and structs References: <33734562 DOT 2756 AT mailbox DOT swipnet DOT se> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Precedence: bulk Krystyna de Heras wrote: > > Hi all! > > I have been coding in C++ for soon four days and while I am porting some > Pascal code I had this idea of optimizing things a little bit also. > > The problem is this: Incrementing pointers in a structure. > > In my thick C++ book it says. > > type *variable=new type[n]; > variable[a]=2; <=> *(variable+a)=2; > > So I began to think. Let's say we have this structure: > > typedef struct clowntype > { > unsigned long int amount_of_pies, balloons; > } clowntype; > > typedef struct cirkustype > { > unsigned long int amount_of_clowns, ticket_cost; > clowntype *clowns; > } cirkustype; > > main bla bla > > cirkustype *cirkus_max= new cirkustype; > > ok here is something I don't know if it's legal > but it compiles allright. > > clowntype *leasing= new clowntype[5]; > cirkus_max->clowns=leasing; // Clowns Points at same as adress as > leasing. > > Now for the problem. > leasing[10].amount_of_pies=12; > THIS WON'T COMPILE > cirkus_max->(*(clowns+10)).amount_of_pies=12; > THIs will compile > cirkus_max->clowns=cirkus_max->clowns+10; > cirkus_max->clowns->amount_of_pies=12; > > Is there a way of indexing clowns without changing its value? Hey I came a up with the answer myself. cirkus_max->clowns=new clowntype[1000]; indexing like this cirkus_max->clowns[666].amount_of_pies=69; If you've read this I'm sorry if it didn't give you any more insight to your massive intelligences, and high iq's ;) NO flames thank you.... Sincerely / Pablo de Heras Hey go here to the download section http://www.efd.lth.se/~d96pd/dl.html