CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: pointer problem

  1. #1
    Join Date
    May 2005
    Posts
    5

    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??

  2. #2
    Join Date
    Jul 2001
    Location
    Trutnov, Czech Republic
    Posts
    459

    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

  3. #3
    Join Date
    May 2005
    Posts
    5

    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

  4. #4
    Join Date
    Mar 2001
    Posts
    2,529

    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

  5. #5
    Join Date
    Apr 2003
    Location
    kathmandu, nepal
    Posts
    1,570

    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
  •  





Click Here to Expand Forum to Full Width

Featured