|
-
May 30th, 2005, 03:52 AM
#1
pointer problem
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??
-
May 30th, 2005, 06:09 AM
#2
Re: pointer problem
I'm not sure but your 'block' inside structure is rather anonymous structure, I would write it rather this way:
Code:
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.
The sun is the same in the relative way, but you're older
Shorter of breath and one day closer to death
- Roger Waters, 1973
-
June 1st, 2005, 11:28 AM
#3
Re: pointer problem
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
-
June 1st, 2005, 11:48 AM
#4
Re: pointer problem
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.
Last edited by ahoodin; June 1st, 2005 at 12:26 PM.
Reason: btw
-
June 1st, 2005, 12:34 PM
#5
Re: pointer problem
Try this;
Code:
r->block::pointer = q->block::pointer;
BTW what errors are you getting?
If there is no love sun won't shine
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|