注册 登录
编程论坛 C++教室

为什么显示不出任何东西?

Jenkin 发布于 2007-04-08 20:24, 492 次点击

我是一个新手,刚刚调试了一个程序,但是显示不出东西。
程序是这样的:
#include<iostream.h>

class Tclass
{
public:
int x,y;
void print()
{
cout<<x<<","<<y<<endl;
};
};

int add(Tclass *ptf)
{
return (ptf->x+ptf->y);
}

void main()
{
Tclass test,*pf;
pf->x=100;
pf->y=200;
pf->print();
test.x=150;
test.y=450;
test.print();
cout<<"x+y="<<add(&test);
}

不知道是什么原因,请各位高手帮我看一下

4 回复
#2
jasonxie2007-04-08 21:10
楼主我和你一样期待答案哈,我也不知道怎么回事也~~~
#3
song42007-04-08 22:42
int x,y;
void print()
{
cout<<x<<","<<y<<endl;
};
Tclass test,*pf;
pf没有空间
#4
帅浪2007-04-09 10:41
回复:(Jenkin)为什么显示不出任何东西?

#include<iostream.h>

class Tclass
{
public:
int x,y;
void print()
{
cout<<x<<","<<y<<endl;
};
};

int add(Tclass *ptf)
{
return (ptf->x+ptf->y);
}

void main()
{
Tclass test,*pf=&test;//我这里改了下
pf->x=100;
pf->y=200;
pf->print();
test.x=150;
test.y=450;
test.print();
cout<<"x+y="<<add(&test);
}
指针没有赋初值,不知道指向哪里!所以运行出错!

#5
jasonxie2007-04-09 13:12
OOOOOOOOOOOOOH~~~~
1