Click to See Complete Forum and Search --> : pointer problem


pro
May 30th, 2005, 03:52 AM
hi
i have a structure such as this
struct node
{
struct block
{ node* pointer;};
int x;
}*p;
when i assign a value to the identifier pointer in any member func of the class in this way an error is generated
//let r and q be node pointers
r->block->pointer=q->block;
why is this so??

s_k
May 30th, 2005, 06:09 AM
I'm not sure but your 'block' inside structure is rather anonymous structure, I would write it rather this way:


struct node
{
struct
{
node* pointer;
} block;
int x;
} *p;


In any case, you assign block structure to pointer to node struct, that's wrong:

r->block.pointer = q

is ok if both r and q are pointers to node structure.

pro
June 1st, 2005, 11:28 AM
ya thanks but how should i go abt it...
struct node
{
struct
{
node *pointer;
}block1,block2;

int data;
};
we have two pointers p(of the node) and q(of the anonymous structure)
..how do i initialize pointer in a member func????plz help

ahoodin
June 1st, 2005, 11:48 AM
definition:

typedef struct book{
}BOOK, *PBOOK;
struct Person
{
int age;
char name[20];
char address[100];
char occupation[50];
PBOOK bible;
};

initialization:

BOOK koran;
Person p={25, "Phileas Fogg", "Saville Row, W1 London", &koran};


HTH,

ahoodin


BTW what do you mean by how do I initialize a pointer in a member func? Which member function where? Please be more specific.

miteshpandey
June 1st, 2005, 12:34 PM
Try this;


r->block::pointer = q->block::pointer;


BTW what errors are you getting?