我是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