我是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;
}
任何意見是非常感謝。
您沒有正確聲明輸入您的postCodeCompare方法,它看起來就像他們是爲了僅僅是你的私有成員。你也確定你想在該方法中增加指針嗎?我建議你切換到'std :: string'來獲得更清晰的功能和更簡單的代碼。 – Nonanon