Mail Archives: djgpp/1997/05/13/14:44:27
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?
- Raw text -