在vc中调试 console程序.#include<iostream.h>
#include<conio.h>void main()
{
point pt;
pt.x=1000;
pt.y=2000; pt.output();
getch();
}class point
{
public:
int x;
int y;
void output()
{
cout<<x<<endl<<y<<endl;
}
};这样会报错改成下面就对了.
#include<iostream.h>
#include<conio.h>class point
{
public:
int x;
int y;
void output()
{
cout<<x<<endl<<y<<endl;
}
};void main()
{
point pt;
pt.x=1000;
pt.y=2000; pt.output();
getch();
}
为什么?难道对main函数的先后位置顺序还有要求吗?
#include<conio.h>void main()
{
point pt;
pt.x=1000;
pt.y=2000; pt.output();
getch();
}class point
{
public:
int x;
int y;
void output()
{
cout<<x<<endl<<y<<endl;
}
};这样会报错改成下面就对了.
#include<iostream.h>
#include<conio.h>class point
{
public:
int x;
int y;
void output()
{
cout<<x<<endl<<y<<endl;
}
};void main()
{
point pt;
pt.x=1000;
pt.y=2000; pt.output();
getch();
}
为什么?难道对main函数的先后位置顺序还有要求吗?
解决方案 »
- 如何在VC下将字符串形式的汉字转换为16进制码
- Good news! I will invite some persons to join our's Blog.
- 请问WSA是什么的缩写呀?比如有个函数是WSAstartup()
- 出现错误error C2146: syntax error : missing ';' before identifier 'SQLHWND'怎么处理?加分!!
- 请问怎样将表名列出来?
- 在VC中如何获取当前目录
- 预编译头文件的问题
- 如何在.sys中返回一个地址给.exe?
- warning C4717: “CcommDlg::OnTimer”: 如递归所有控件路径,函数将导致运行时堆栈溢出
- 为什么AfxMessageBox()函数使程序死了,请高手帮助!
- mfc 需要屏蔽一些 按钮功能,start后才启动按钮功能。
- 在对话框中取得BomboBox的当前显示位置
#include<conio.h>
class point;
void main()
{
point pt;
pt.x=1000;
pt.y=2000; pt.output();
getch();
}class point
{
public:
int x;
int y;
void output()
{
cout<<x<<endl<<y<<endl;
}
};
class point
{
public:
int x;
int y;
void output()
{
cout<<x<<endl<<y<<endl;
}
};
放在main函数之前。
当然,你还可以向楼上一样,先声明class point;
这时候main中用到 point pt;
时就知道point是一个类了。
这个问题除了定义类,还有定义结构,函数都是一样。比如:#include<iostream.h>void main()
{
int nNum = fun();
}
int fun()
{
return 0;
}
上面的程序也会报错
解决方法如下:
#include<iostream.h>int fun();void main()
{
int nNum = fun();
}
int fun()
{
return 0;
}当然如果你非要把类的定义放在下面,你的程序也可以找房抓药改为:
7楼说的样子,正解所以,你可以看到,一般使用VC的是,对于一个类的定义会分为两个文件,一个是.h文件,一个是.cpp文件
一般.h文件里面全部都是定义部分,实现部分在.cpp文件中,使用时直接把.h文件include了,就把定义全都包含了嘻嘻~这种问题在以后VC中使用全局函数时会时时出来,嘻嘻~多看看书,慢慢就明白了~嘻嘻