0

I am a beginner in C++,I have a linked list defined in main I give it to a function as a parameter,inside that function the list is changed but when the program comes out from the function the linked list is unchanged what should I do? it's like this

mnlist nodes;
nodes.first = NULL:
typelist typel;
typel.first = NULL;
nodes = list-scheduling(nodes,typel);//this is my function

but typel doesn't change when program exits from list-scheduling

2
  • 2
    What's the signature of your function? (In other words, could you please show us your function?). Feb 8, 2013 at 6:09
  • 4
    Pass by value/Pass by refernce
    – user2166576
    Feb 8, 2013 at 6:10

2 Answers 2

1

(I don't know how a function with the name "list-scheduling" compiled...)

Anyways, use references. Instead of

void foo(LinkedList l);

declare it as

void foo(LinkedList &l);
2
  • 1
    Maybe his subtracting the result of scheduling() from an object called list... :-) Feb 8, 2013 at 6:15
  • @MarkGarcia LOL, fair enough.
    – user529758
    Feb 8, 2013 at 6:16
0

You should Read this

Pass by value :

int n =10
function(int n)
{
n++;
cout<<n ;  //n==11
}
cout<<n ; //n=10. only local value changes

pass by refernce :

int n=10;
function(int &n)
{
n++;
cout<<n ; //n=11
}
cout<<n; //n=11. Passed address of n, so changes will reflect
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.