I am trying to declare a function to find the largest mobile element for a program to list permutations using johnson-totter algorithm. Here is my definition of the function in the header file:
int findMobile( string, int[] );
and here is my actual declaration of the function:int findMobile( string word, int[] dir ){
and the error I am getting is
error: expected ',' or '...' before 'dir', error: 'dir' was not declared in this scope
I was looking at an article that had function declartions with arrays as reference and they did something exactly as this but mine isn't working. Am I missing something obvious? This is my first class using c++ but it is not about learning the language it is about data structures and algorithms so it is assumed we have backgrounds in other languages and we can just pick this one up quickly. What is the problem with this function? The call looks like:
index = findMobile( word, dir );
and dir
is declared by the following line:int dir [index]
but that shouldn't even matter as passing the array to the function doesn't actually care what variable I am passing it is just looking for an argument that matches the type and that is where my problem is, it isn't allowing me to make a function with an int array as an argument. I tried int*
using pointers but it has been a long time since I've used a pointer and that just resulted in a segfault because I wasn't sending references or using the pointer right or anything. Can anyone help, I will provide any answers to questions that I can. I don't want to put the entire code out there just because we are supposed to do this on our own and I think the code will work but I can't test it because it won't compile. If it doesn't work then I may need to ask some questions.