调用C++;函数并更改其参数(链表) 我是C++的初学者,我在主链中定义了一个链表,我把它作为函数来作为一个参数,在这个函数中,列表被改变了,但是当程序从函数中出来,链表不变时,我该怎么办? 是这样的 mnlist nodes; nodes.first = NULL: typelist typel; typel.first = NULL; nodes = list-scheduling(nodes,typel);//this is my function

调用C++;函数并更改其参数(链表) 我是C++的初学者,我在主链中定义了一个链表,我把它作为函数来作为一个参数,在这个函数中,列表被改变了,但是当程序从函数中出来,链表不变时,我该怎么办? 是这样的 mnlist nodes; nodes.first = NULL: typelist typel; typel.first = NULL; nodes = list-scheduling(nodes,typel);//this is my function,c++,function,pointers,linked-list,C++,Function,Pointers,Linked List,但当程序退出列表调度时,typel不会改变(我不知道名为“列表调度”的函数是如何编译的…) 无论如何,使用参考资料。而不是 void foo(LinkedList l); 宣布为 void foo(LinkedList &l); 你应该读书 通过值: int n =10 function(int n) { n++; cout<<n ; //n==11 } cout<<n ; //n=10. only local value changes int n=10

但当程序退出列表调度时,typel不会改变(我不知道名为“列表调度”的函数是如何编译的…)

无论如何,使用参考资料。而不是

void foo(LinkedList l);
宣布为

void foo(LinkedList &l);
你应该读书

通过值:

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

你的函数的签名是什么?(换句话说,你能给我们看一下你的函数吗?)。按值传递/按引用传递可能是他从一个名为
list
…:-)@MarkGarcia LOL的对象中减去
scheduling()
的结果,这很公平。
int n=10;
function(int &n)
{
n++;
cout<<n ; //n=11
}
cout<<n; //n=11. Passed address of n, so changes will reflect