2016-11-11 4 views
-1

私はC++を使い慣れていますので、これは愚かな質問です。私は、そのパラメータで3つの配列を持つ関数を作成しようとしています。私は、それぞれが宣言されていないというエラーが出ています。ヘッダ内関数内のC++配列のパラメータが宣言されていません

コード: #ifndefのADDRESSMODEL の#define ADDRESSMODELの#define ADDRESSDEBUG主に

#include <iostream> 
#include <string.h> 


using namespace std; 
class PostCode 
{ 
public: 
    PostCode(void); 
    ~PostCode(); 
    void postCodeCompare(tempPostCode[], theRoutingArray[], theIdentifier[]); 

private: 

    char theRoutingArray[4]; 
    char theIdentifier[5]; 
    char tempPostCode[8]; 
}; 

inline PostCode :: PostCode(void) 
{ 
    strcpy(theRoutingArray, "000"); 
    strcpy(theIdentifier, "0000"); 
    cout << "Debug constructor called" << endl; 
} 

inline PostCode :: ~PostCode() 
{ 
    cout<< "Destructor" << endl; 
} 

inline int PostCode :: postCodeCompare(tempPostCode, theRoutingArray, theIdentifier) 
{ 
    char postCode[] = theRoutingArray + theIdentifier; 
    if (postCode[0] == tempPostCode[0]){ 
     cout << 1 << endl; 
    } 
    else{ 
     cout << 0 << endl; 
    } 
} 



#endif 

コード: の#include "がheader.h" 名前空間stdを使用。

int main(void){ 
cout << "main has started" << endl; 

PostCode myCode; 
char theRoutingArray[4]; 
char theIdentifier[5]; 
char tempPostCode[8]; 

cout << "Please type in your routing key: " << endl; 
cin.getline(theRoutingArray, 4); 

cout << "Please type in your identifier: " << endl; 
cin.getline(theIdentifier, 5); 

PostCode.postCodeCompare(); 

cout << "main has finished" << endl; 


return 0; 

} 

アドバイスをいただければ幸いです。

+0

あなたが適切に彼らはちょうどあなたのプライベートなメンバーであることを意味しているように見えるあなたのpostCodeCompareメソッドへの入力を、宣言していません。また、そのメソッドにポインターを追加してもよろしいですか?より明確な機能とより簡単なコードを得るために 'std :: string'に切り替えることをお勧めします。 – Nonanon

答えて

0

アドバイス:基本を説明する良いC++の本を読んでください。 C++ Primer 5th editionがその例です。

配列パラメータのためのあなたの構文が正しくありません:あなたはタイプ宣言で配列要素のを逃している、とあなたが欠落している両方の要素タイプとで「配列構文」定義。

また、定義と宣言の間に戻り型が一致しません。

void postCodeCompare(char tempPostCode[], char theRoutingArray[], char theIdentifier[]); 

...

inline int PostCode :: postCodeCompare(
    char tempPostCode[], char theRoutingArray[], char theIdentifier[]){ /*...*/ } 
+0

残念ながら、私はまだ同じエラー "tempPostCode []が宣言されていません"を取得しています。 –

+0

リターンタイプの不一致もあります。 'postCodeCompare'は' void'として宣言され、 'int'として定義されます。ここには[**動作例**](http://melpon.org/wandbox/permlink/sUcitjYNU9HPZcuH)があります。 C++の本を読んでください! –

関連する問題