0

I need to be able to pass a 2D array into my function but I don't know the exact size of the array being passed before running it because the size of the array will be random. I also don't have control of the main function. The function I need to pass the array into is called Pathfinder and the call to it in main is Pathfinder(arr) and that can't be changed.

I've tried many different things including templates and pointers but with that function call I keep getting errors such as that the second value of the array needs to be instantiated and can't just be []

Templates might work but I don't think I implemented them correctly

char arr[15][20] ={{'s','w','e','e','e','e','e','e','e','e','e','e','e','e','e','e','e','e','e','e'},{'e','w','e','e','e','e','e','e','e','e','e','e','e','e','e','e','e','e','e','e'},{'e','w','e','w','w','w','w','w','w','w','w','w','w','w','w','w','e','w','w','w'},{'e','w','e','w','b','e','e','e','e','e','e','e','e','e','e','e','e','w','g','g'},{'e','w','e','w','w','w','w','w','w','w','w','w','w','w','w','w','e','w','g','g'},{'e','w','e','w','e','e','e','e','e','e','e','e','e','e','e','e','e','w','g','g'},{'e','w','e','w','e','w','w','w','w','w','w','w','e','e','e','e','e','w','g','g'},{'e','w','e','w','e','e','e','e','e','e','e','w','e','w','w','w','w','w','w','e'},{'e','w','e','w','e','e','b','e','e','e','w','w','e','w','e','e','e','e','w','e'},{'e','w','e','w','e','g','b','f','e','e','w','e','e','w','e','w','w','e','w','e'},{'e','w','e','w','e','e','b','e','g','g','w','e','e','w','e','e','w','e','w','e'},{'e','w','e','w','e','e','e','e','e','e','w','w','e','w','e','e','w','e','e','e'},{'e','w','e','w','e','e','e','e','e','e','e','w','e','w','e','e','w','e','e','e'},{'e','e','e','w','e','e','e','e','e','e','e','w','e','w','w','w','w','e','e','e'},{'e','w','e','w','e','e','e','e','e','e','w','e','e','e','e','e','e','e','e','e'},};

pathfinder(arr)

This is the function call from main and I have no control over that

vector<char> pathfinder(char arr[][])

This is my current function declaration but it doesn't work. It also has to be an array that's being passed in and can't be a vector because I can't change it. I can't do any global variables in main as I have no control over main for it will be provided for me, my function implementation and the relevant files are the only things I have control over

Harrison
  • 23
  • 5
  • Use `std::vector` or `std::string`. – πάντα ῥεῖ Apr 18 '19 at 20:35
  • _"... because the size of the array will be random..."_ use `std::vector` – Richard Critten Apr 18 '19 at 20:35
  • 1
    "I've tried many different things including templates and pointers but with that function call I keep getting errors such as that the second value of the array needs to be instantiated and can't just be []" Interesting because if your declaration was `vector pathfinder(char * arr)` then `pathfinder((char*)&arr[0][0]);` works...just saying – bigwillydos Apr 18 '19 at 20:51

0 Answers0