Message-ID: <33734562.2756@mailbox.swipnet.se> Date: Tue, 13 May 1997 20:40:18 -2000 From: Krystyna de Heras MIME-Version: 1.0 To: djgpp AT delorie DOT com Subject: HELP! Pointers and structs Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Precedence: bulk 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?