좋아, 그래서있어 3 개 파일 :오버로드 기능, 재정의, C2371 및 C2556 C++
#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;
}
등을 포함
#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
functions.cpp을 포함
definitions.h 주요 프로그램은 다음을 포함합니다 :
#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);
하지만 오류 C2371 계속 : 재정의; 및 C2556 : 오버로드 된 함수는 반환 유형에 의해서만 차이가 있습니다.
온라인에서 찾은 모든 것이 function.cpp 파일이 주에 포함되지 않았 음을 의미하지만 실행하지 않고 있습니다. 아이디어에서, 특히 같은 방식으로 (별개의 정의와 선언으로) 설정된 다른 모든 기능이 작동하는 것처럼 보입니다.
도움이 될 것입니다. 감사 H X
무엇이 재정의됩니까? 오류 메시지의 실제 내용은 무엇입니까? 코드에 아무 것도 없을 때 오버로드에 대해 묻는 이유는 무엇입니까? 왜 같은 함수에서 4 개의 return 문을 차례로 가지게됩니까? topolar 함수에 매개 변수로 지역 변수를 전달하는 이유는 무엇입니까? main 함수에서'count'의 값은 무엇입니까? 닫는 괄호는 어디에 있습니까? 왜 새 변수를 사용하여 지역 변수를 할당하고 있습니까? 여기에는 많은 문제가 있습니다. –
definitions.h에서 선언 된 클래스가 닫혀 있지 않은 상태로 남아 있습니까? – milliburn