未声明函数内的 C++ 数组参数

C++ array parameters inside function not being declared

我是 C++ 的新手,如果这是一个愚蠢的问题,我深表歉意。我正在尝试创建一个在其参数中包含 3 个数组的函数。我得到的错误是它们中的每一个都没有被声明。

header 中的代码: #ifndef 地址模型 #define 地址模型 #define 地址调试

#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" 使用命名空间标准;

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;

}

非常感谢任何建议。

建议: 阅读一本介绍基础知识的优秀 C++ 书籍。 C++ Primer 5th edition 是一个例子。

您的数组参数语法不正确:您在声明中缺少数组元素的 类型 ,并且缺少元素 type和定义中的"array syntax".

此外,您在定义和声明之间存在 return 类型不匹配。

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

...

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