[問題] 不太懂錯在哪 想請問一下指標的問題
我不想要主程式裡直接宣告一個空間給*a 跟 *b
想要在副程式裡再宣告空間給它
請問一下大家我這樣寫哪邊有問題
我實在不太瞭解...謝謝大家了
#include <iostream>
#include <conio.h>
#include <string.h>
using namespace std;
struct node
{
string name;
node *next;
};
void get_data(struct node *);
int main()
{
node *a,*b,c;
get_data(a);
get_data(b);
cout << "a=" << a->name <<endl;
cout << "b=" << b->name <<endl;
delete a;
delete b;
getch();
return 0;
}
void get_data(struct node *data)
{
node *tmp;
tmp = new node;
cout << "name=";
cin >> tmp->name;
tmp->next=NULL;
data=tmp;
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 134.208.2.154
推
09/01 14:00, , 1F
09/01 14:00, 1F
→
09/01 14:01, , 2F
09/01 14:01, 2F
推
09/01 14:02, , 3F
09/01 14:02, 3F
推
09/01 14:03, , 4F
09/01 14:03, 4F
→
09/01 14:04, , 5F
09/01 14:04, 5F
推
09/01 14:06, , 6F
09/01 14:06, 6F
→
09/01 14:08, , 7F
09/01 14:08, 7F
推
09/01 14:08, , 8F
09/01 14:08, 8F
→
09/01 14:09, , 9F
09/01 14:09, 9F
→
09/01 14:09, , 10F
09/01 14:09, 10F
→
09/01 14:10, , 11F
09/01 14:10, 11F
→
09/01 14:15, , 12F
09/01 14:15, 12F
→
09/01 14:16, , 13F
09/01 14:16, 13F
→
09/01 14:17, , 14F
09/01 14:17, 14F
→
09/01 14:17, , 15F
09/01 14:17, 15F
→
09/01 14:19, , 16F
09/01 14:19, 16F
推
09/02 09:01, , 17F
09/02 09:01, 17F
→
09/02 09:03, , 18F
09/02 09:03, 18F
→
09/02 09:03, , 19F
09/02 09:03, 19F