1

I'm trying to pass a 2d and single dimmension array of strings to a function but its not working.

my arrays are:

    string 2Darray[100][100];
    String 1Darray[100];

Now the function:

    void check(string temp2D[100][100], string temp1D[100]);

When I call it:

    check(2Darray,1Darray);

I've tried it other ways ad they all don't work. Thanks in advance for any answers!

3
  • 2
    your 1Darray seems 2D to me Commented Mar 12, 2013 at 3:23
  • string 1Darray ,being a 1D array has two sets of indices , in its declaration ?? Commented Mar 12, 2013 at 3:25
  • You cannot start identifiers with numbers in C++, i.e. 2Darray needs to be twoDarray, etc. Commented Mar 12, 2013 at 3:28

1 Answer 1

3

You could change to accept references:

void check(string (&temp2D)[100][100], string (&temp1D)[100]);

or pointers:

void check(std::string temp2D[][100], std::string temp1D[]){}

which is the same as the following just different syntax:

void check(std::string (*temp2D)[100], std::string* temp1D){}

Also, you cannot start variable names with numbers, 2Darray, etc. is a compiler error.

Here is a full working example:

#include <string>

void check(std::string (&temp2D)[100][100], std::string (&temp1D)[100]){}

int main()
{
    std::string twoDarray[100][100];
    std::string oneDarray[100];
    check(twoDarray,oneDarray);
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.