自定义的函数是不是都得有参数呀?
比如说
void xx(int x)
{
cout << "XXXXX" << endl;
}
int main()
{
//调用时就得加上参数
xx(0);
//为什么不能像系统函数一样 像这样
getch();
}
2楼的可以了不过这个警告怎么去掉? 我新手好多地方都不懂!
1>.\Window.cpp(23) : warning C4996: “getch”被声明为否决的
1> E:\VS\VC\include\conio.h(145) : 参见“getch”的声明
1> 消息:“The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _getch. See online help for details.”
C++中定义没有参数的函数有两种方法。
方法1(空括号法):
返回值类型 函数名()
{
函数体;
}
例如:
int getarand()方法2(强调法):
返回值类型 函数名(void)
{
函数体;
}
int getarand(void)