首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

指针参数有关问题 求指教

2013-02-15 
指针参数问题 求指教#include stdafx.h#include iostreamusing namespace stdclass Test{public:int

指针参数问题 求指教
#include "stdafx.h"
#include <iostream>
using namespace std;
class Test{
public:
int x;
int y;
};

void init(Test *t)
{
t = new Test;
t->x = 1;
t->y = 2;

}

int _tmain(int argc, _TCHAR* argv[])
{
Test *a = NULL;
init(a);
cout<<a->x<<endl;
return 0;
}

为什么这样初始化一个指针的时候不行呢
[解决办法]
注意区分,值传递与地址传递。根据,你的void init(Test *t)
函数而言,应该是,你使用指针来起到地址传递的作用吧,那么,你的main()里面的实参,就不要定义成指针了。或者说,init(&a)

热点排行