寻找地理和伤害意味着超载
Finding geo and harm mean overloading
我正在为一个类做一个项目,我遇到了一些麻烦,这给了我 2 个错误,我不明白它们是什么意思...... 它给出了错误:c4716 "medie" 必须返回一个值。
这是代码:
#include <iostream>
#include <stdlib.h>
#include<math.h>
using namespace std;
float medie(float a, float b, float c)
{
float MG,MA;
MG= sqrt(a*b*c);
cout<< "MG="<< MG<<endl;
MA=(2*a*b*c)/(a+b+c);
cout<< "MA="<< MA<<endl;
}
float medie(float a,float b,float c,float d)
{
float MG,MA;
MG= sqrt(a*b*c*d);
cout<< "MG="<< MG<<endl;
MA=(2*a*b*c*d)/(a+b+c+d);
cout<< "MA="<< MA<<endl;
}
int main()
{
float a,b,c,d;
cout<<"a="<<endl;
cin>>a;
cout<<"b="<<endl;
cin>>b;
cout<<"c="<<endl;
cin>>c;
cout<<"d="<<endl;
cin>>d;
medie(a,b,c);
medie(a,b,c,d);
}
您的medie
函数声明为返回一个float
值,但其中没有任何return
语句。如果声明它们返回void
则错误应该消失。
#include <iostream>
#include <stdlib.h>
#include <math.h>
using namespace std;
void medie(float a, float b, float c)
{
float MG,MA;
MG = sqrt(a*b*c);
cout<< "MG="<< MG<<endl;
MA = (2*a*b*c)/(a+b+c);
cout<< "MA="<< MA<<endl;
}
void medie(float a,float b,float c,float d)
{
float MG,MA;
MG = sqrt(a*b*c*d);
cout<< "MG="<< MG<<endl;
MA = (2*a*b*c*d)/(a+b+c+d);
cout<< "MA="<< MA<<endl;
}
int main()
{
float a,b,c,d;
cout<<"a="<<endl;
cin>>a;
cout<<"b="<<endl;
cin>>b;
cout<<"c="<<endl;
cin>>c;
cout<<"d="<<endl;
cin>>d;
medie(a,b,c);
medie(a,b,c,d);
}
相关文章:
- 这行代码在C++类中意味着什么
- 这对"With a stackless coroutine, only the top-level routine may be suspended."意味着什么
- 寻找地理和伤害意味着超载
- 没有可行的超载'='用于shared_ptr
- "专业化不参与超载"
- @CPPFLAGS@在 Makefile.in 中意味着什么?
- 在C++标准中做格式好意味着代码可以编译
- 生成文件"relink"意味着什么?
- 虚拟超载运算符>>和<<
- 从二进制流中读取时,将双精度变量的地址转换为 char* 意味着什么?
- 在这种情况下,"typename..."意味着什么?
- C++评估顺序优化是否意味着对不同的操作数使用不同的内核?
- "in-situ without memory allocation" 字符串的愚蠢实现意味着什么?
- 使用typedef有什么用,它意味着什么
- GCC 的 -Wpsabi 选项究竟有什么作用?压制它意味着什么?
- 为什么我的超载"+"运算符返回的总额错误?
- 负指数是否必然意味着未定义的行为
- c++ 提升如果 .extension() == " "这意味着这个文件是一个文件夹?
- 这在C++ "It does not own the underlying data, and so is cheap to copy or assign"中意味着什么
- 删除K的背景掩码-意味着Python或C++中的集群/