指针的传递并不是构造副本

来源:互联网 发布:js脚本怎么用 编辑:程序博客网 时间:2024/06/07 11:55
#include <iostream>#include <string>#include <algorithm>#include <cstring>#include <stack>using namespace std;struct Node {    char ch;    int val;    string code;    Node* l;    Node* r;    Node (int wei,int index):ch('A'+index),val(wei),l(NULL),r(NULL),code(""){}};void f(Node* k) {    k->val = 15;}int main() {    stack<Node*> s;    Node* tmp = new Node (23,0);    s.push(tmp);    cout<<s.top()->val<<" "<<s.top()->ch<<endl;    tmp->val = 30;    cout<<s.top()->val<<" "<<s.top()->ch<<endl;    f(s.top());    cout<<s.top()->val<<" "<<s.top()->ch<<endl;}
0 0
原创粉丝点击