2012-03-22 25 views
0

[OK]をので、私が持っている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:オーバーロードされた関数differesは戻り値の型でしかありません

オンラインで見つかったことは、function.cppファイルがメインに含まれていないことを確認するためですが、私はそのミスを実行していませんアイデアから、特に同じ方法で(別々の定義と宣言を使って)設定されている他のすべての関数が動作するように見える。

助けがあれば助かります。 おかげ H X

+0

何が再定義されていますか?エラーメッセージの実際の内容は何ですか?なぜコードに何もないときにオーバーロードについて質問していますか?なぜ同じ関数内で4つのreturn文が次々にあるのですか? topolar関数にパラメータとしてローカル変数を渡すのはなぜですか? main関数の 'count'の値は何ですか?閉じ括弧はどこですか?なぜ新しい変数をローカル変数に割り当てるのですか?ここには多くの問題があります。 –

+1

definitions.hで宣言されているクラスは閉じられていないはずですか? – milliburn

答えて

2

宣言topolar関数は、二重返す必要がありますが、functions.cppでの定義が

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

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

あなた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; 
関連する問題