【发布时间】:2017-03-25 15:13:11
【问题描述】:
我是 C++ 新手,如果这是一个愚蠢的问题,我深表歉意。我正在尝试创建一个在其参数中包含 3 个数组的函数。我收到了一个错误,即它们中的每一个都没有被声明。
标题中的代码: #ifndef 地址模型 #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 "头文件.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;
}
非常感谢任何建议。
【问题讨论】:
-
您没有正确声明 postCodeCompare 方法的输入,看起来它们只是您的私人成员。您还确定要在该方法中添加指针吗?我建议你切换到
std::string以获得更清晰的功能和更简单的代码。
标签: c++ arrays function parameters display