Need help with pointer data member

I have a linked list and I use a function that will get user input and store it in the list data members, my issue is with one of them, 'id' if a parameter doesn't meet requirements of an if-statement it should call a function and the function it calls should be able to store the value, when all requirements are met, to the data member in this case temp->data. What I tried to do to pinpoint the problem was make a small program to see if I could get it to work so here's what I came up with(note, this does not work, this is what I need help on):

struct node {
int data;
node* next;
};

void test(int *&a)
{
a->data = 399;
};
int main()
{
node* mine = NULL; /* NOTE THIS IS THE ATTEMPT AT SOLVING MY PROBLEM
BUT ALL THIS CODE DID NOT SOLVE MY PROBLEM */
mine = new node;
mine->data = 77;
mine->next = NULL;
cout << &mine->data;
test(*mine);
return 0;
}


I want to pass the data member to the test function and have it return the new stored mine->data value using the function. I need help understanding how to do this.
In your test function, a is a reference to a pointer-to-int. It does not have a "data" member.
If you wish to pass your node object by reference, then do something like:

1
2
3
4
void test(node& node_obj)
{
    node_obj.data = 399;
}
Last edited on
Topic archived. No new replies allowed.