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

时间:2016-11-11 11:33:36

标签: c++ arrays function parameters display

我是C ++的新手,如果这是一个愚蠢的问题,请道歉。我试图在其参数中创建一个3个数组的函数。我收到的错误是他们每个人都没有被宣布。

标头中的

代码:     #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&#34; Header.h&#34; 使用namespace 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;

}

非常感谢任何建议。

1 个答案:

答案 0 :(得分:0)

建议:阅读一本很好的C ++书籍来解释基础知识。 C++ Primer 5th edition就是一个例子。

您对数组参数的语法不正确:您在声明中缺少数组元素的类型,并且您缺少元素类型和定义中的“数组语法”

此外,定义和声明之间的返回类型不匹配。

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

...

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