Eoin Coogan Eoin Coogan - 9 months ago 39
C++ Question

C++ array parameters inside function not being declared

I'm new to C++ so apologies if this is a stupid question. I'm trying to create a function that 3 arrays in its parameter. I'm getting the error that each one of them isn't being declared.

code in header:

#include <iostream>
#include <string.h>

using namespace std;
class PostCode
void postCodeCompare(tempPostCode[], theRoutingArray[], theIdentifier[]);


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;
cout << 0 << endl;


Code in main:
#include "Header.h"
using 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);


cout << "main has finished" << endl;

return 0;


Any advice is much appreciated.

Answer Source

Advice: read a good C++ book that explains the basics. C++ Primer 5th edition is an example.

Your syntax for the array parameters is incorrect: you're missing the type of the array elements in the declaration, and you're missing both the element type and the "array syntax" in the definition.

Additionally, you have a return type mismatch between the definition and the declaration.

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


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