C++ 重载函数,重新定义,C2371和C2556 C++;

C++ 重载函数,重新定义,C2371和C2556 C++;,c++,overloading,redefinition,C++,Overloading,Redefinition,好的,我有3个文件: 定义.h其中包含 #ifndef COMPLEX_H #define COMPLEX_H class Complex { char type; //polar or rectangular double real; //real value double imaginary; //imaginary value double length; //length if polar double angle; //angle if polar public: //co

好的,我有3个文件:

定义.h其中包含

#ifndef COMPLEX_H 
#define COMPLEX_H 
class Complex
{

char type; //polar or rectangular
double real; //real value 
double imaginary; //imaginary value
double length; //length if polar
double angle; //angle if polar

 public:
//constructors
Complex();
~Complex();
void setLength(double lgth){ length=lgth;}
void setAngle(double agl){ angle=agl;}
double topolar(double rl, double img, double lgth, double agl);
#endif
#include "Class definitions.h"
#include <iostream>
#include <fstream>
#include <iomanip> 
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
using namespace std;

Complex::topolar(double rl, double img, double lgth, double agl)
{
real=rl;
imaginary=img;  
lgth = sqrt(pow(real,2)+pow(imaginary,2));
agl = atan(imaginary/real);
Complex::setLength(lgth);
Complex::setAngle(agl);

return rl;
return img;
return lgth;
return agl;

}
functions.cpp,其中包含

#ifndef COMPLEX_H 
#define COMPLEX_H 
class Complex
{

char type; //polar or rectangular
double real; //real value 
double imaginary; //imaginary value
double length; //length if polar
double angle; //angle if polar

 public:
//constructors
Complex();
~Complex();
void setLength(double lgth){ length=lgth;}
void setAngle(double agl){ angle=agl;}
double topolar(double rl, double img, double lgth, double agl);
#endif
#include "Class definitions.h"
#include <iostream>
#include <fstream>
#include <iomanip> 
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
using namespace std;

Complex::topolar(double rl, double img, double lgth, double agl)
{
real=rl;
imaginary=img;  
lgth = sqrt(pow(real,2)+pow(imaginary,2));
agl = atan(imaginary/real);
Complex::setLength(lgth);
Complex::setAngle(agl);

return rl;
return img;
return lgth;
return agl;

}
#包括“Class definitions.h”
#包括
#包括
#包括
#包括
#包括
#包括
#包括
使用名称空间std;
复合:拓扑(双rl、双img、双lgth、双agl)
{
real=rl;
假想的=img;
lgth=sqrt(功率(实,2)+功率(虚,2));
agl=atan(虚/实);
复数::setLength(lgth);
复合物:设定角(agl);
返回rl;
返回img;
返回lgth;
返回agl;
}
主要方案包括:

#include "Class definitions.h"
#include <iostream>
#include <fstream>
#include <iomanip> 
#include <string.h>
#include <cmath>
#include <vector>
using namespace std;

int main(){

vector<Complex> v;
Complex *c1;
double a,b,d=0,e=0;
c1=new Complex;
v.push_back(*c1);
v[count].topolar(a,b,d,e);
#包括“Class definitions.h”
#包括
#包括
#包括
#包括
#包括
#包括
使用名称空间std;
int main(){
向量v;
复合物*c1;
双a,b,d=0,e=0;
c1=新复合体;
v、 推回(*c1);
v[计数]。拓扑(a,b,d,e);
但我不断得到错误C2371:重新定义;不同的基本类型 和C2556:重载函数仅按返回类型不同

我在网上找到的所有内容都是为了确保function.cpp文件不包含在main中,但由于我没有犯这个错误,我已经没有什么想法了,尤其是当我看到所有其他以相同方式设置的函数(使用单独的定义和声明)都可以工作时

任何帮助都会很好! 谢谢 H
声明的拓扑函数应该返回double,但是functions.cpp中的定义没有这样说

Complex::topolar(double rl, double img, double lgth, double agl)
{
尝试将此更改为

double Complex::topolar(double rl, double img, double lgth, double agl)
{

声明的topolar函数应该返回double,但是functions.cpp中的定义没有这样说

Complex::topolar(double rl, double img, double lgth, double agl)
{
尝试将此更改为

double Complex::topolar(double rl, double img, double lgth, double agl)
{

您的
topolar
函数定义为返回
double
,但实现没有返回类型。我不确定这是否是错误,但肯定是错误。您需要

double Complex::topolar(double rl, double img, double lgth, double agl)
在执行中

此外,您的实现中似乎有许多return语句。这也是一个错误。只有第一个语句有效:

return rl; // function returns here. The following returns are never reached.
return img;
return lgth;
return agl;

您的
topolar
函数定义为返回
double
,但实现没有返回类型。我不确定这是否是错误,但肯定是错误。您需要

double Complex::topolar(double rl, double img, double lgth, double agl)
在执行中

此外,您的实现中似乎有许多return语句。这也是一个错误。只有第一个语句有效:

return rl; // function returns here. The following returns are never reached.
return img;
return lgth;
return agl;

重新定义了什么?错误消息的实际内容是什么?当代码中没有重载时,为什么要询问重载?为什么在同一个函数中有4个返回语句?为什么要将局部变量作为参数传递给拓扑函数?主函数中的
count
值是多少ION?结束括号在哪里?为什么要使用new来分配局部变量?这里有很多问题。定义中声明的类。h应该保持未关闭状态吗?重新定义了什么?错误消息的实际内容是什么?为什么在代码中没有重载时问重载?为什么有4个return语句在同一个函数中一个接一个地出现?为什么要将局部变量作为参数传递给拓扑函数?主函数中的
count
值是多少?右括号在哪里?为什么要使用new来分配局部变量?这里有很多问题。类是在定义中声明的吗o不关闭?