呼市邮编回民区:这段C++代码哪错了
来源:百度文库 编辑:杭州交通信息网 时间:2024/06/14 21:04:55
class fac{
private:
int a,b;
public:
int fac(int n)
{
int y,x=1;
for (y>=1;y<=n;y++)
{
x=x*y;
}
printf("%d",x);
};
};
错误信息:构造函数不允许一个返回类型
程序应该怎么改?请高手赐教
int fac(int n)改成
void fac(int n)
还有相同的错误
private:
int a,b;
public:
int fac(int n)
{
int y,x=1;
for (y>=1;y<=n;y++)
{
x=x*y;
}
printf("%d",x);
};
};
错误信息:构造函数不允许一个返回类型
程序应该怎么改?请高手赐教
int fac(int n)改成
void fac(int n)
还有相同的错误
#include <iostream.h>
class fac
{
private:
int a,b;
public:
int fac(int n)
{
int y,x=1;
for (y>=1;y<=n;y++)
{
x=x*y;
}
cout<<"n的阶乘是:"<<x<<endl;
}
};
void main()
{
int a;
cout<<"请输入n:";
cin>>a;
fac h(a);
}
int fac(int n)改成
void fac(int n)
还有相同的错误
是因为构造函数不能为空值型
int fac(int n)
void fac(int n)
for (y>=1;y<=n;y++)
改为 for (y=1;y<=n;y++)
我想是因为这个有问题吧《int fac(int n) 》这个里面的int n可能不要,或者说改为其它的吧(如int m,int n)!!!!!
构造函数前不加返回类型,它也没有返回任何一个数据类型,只是初始化作用。建议好好看看C++教程。