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

有关指针参数的有关问题

2013-02-02 
有关指针参数的问题#include stdafx.h#include iostreamusing namespace stdclass Test{public:int x

有关指针参数的问题
#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;
}

这样初始化指针为什么会报错呢
[解决办法]
t是个局部变量,a只是把自己的值传递给t而已,new到的给了t而没有给a,所以a还是个空指针

热点排行