非法使用void的问题怎么解决??

mu969lan 2015-02-26 05:24:49
这样写的问题在哪?求指点!
主程序代码(hdatei.cpp):
#include<iostream>
#include"malen.h"
using namespace std;

int main() {
int a=5;
void malen(a);
}

头文件(malen.h):
void malen(int);

头文件执行文件(malen.cpp):
#include<iostream>
using namespace std;
void malen(int a) {
for(int i=a;i>0;i--){
for(int k=(a-i);k>0;k--)
cout<<" ";
for(int j=(2*i-1);j>0;j--)
cout<<"*";
cout<<endl;}
}
...全文
2388 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
招财猫_Martin 2015-03-02
  • 打赏
  • 举报
回复
请把报错信息发来看看。
mu969lan 2015-02-26
  • 打赏
  • 举报
回复
引用 1 楼 promaster 的回复:
main函数里,调用的时候malen(a)前面不要加void。 函数调用的时候,如果返回类型是void,相当于一个过程调用。
嗯,我之前删了void还是提示错误,不过现在再去删发现确实成功了,谢谢! 不过我之前类似的一个程序调用删了void还是出错,可以麻烦看下吗? 主程序: #include<iostream> #include"strich.h" using namespace std; void main() { int x; cin>>x; strich(x); } 头文件: void strich(int); 头文件执行文件: #include<iostream> using namespace std; void srtich(int x) { for(int a=x; a>0; a--) { for(int b=(a-1); b>0; b--) cout<<" "; cout<<"*"<<endl; } }
mu969lan 2015-02-26
  • 打赏
  • 举报
回复
嗯,我之前删了void还是提示错误,不过现在再去删发现确实成功了,谢谢!
不过我之前类似的一个程序调用删了void还是出错,可以麻烦看下吗?
主程序:
#include<iostream>
#include"strich.h"
using namespace std;

void main() {
int x;
cin>>x;
strich(x);
}

头文件:
void strich(int);

头文件执行文件:
#include<iostream>
using namespace std;
void srtich(int x)
{
for(int a=x; a>0; a--)
{
for(int b=(a-1); b>0; b--)
cout<<" ";
cout<<"*"<<endl;
}
}
招财猫_Martin 2015-02-26
  • 打赏
  • 举报
回复
main函数里,调用的时候malen(a)前面不要加void。 函数调用的时候,如果返回类型是void,相当于一个过程调用。

19,468

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 图形处理/算法
社区管理员
  • 图形处理/算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧