I am attempting to return a multidimensional array from within a function of a class. Is this possible?
I can only get the data by making the array public and using user.line[a][b] to get the data. Is it possible to get the data from line[a][b] from int main()?
a = a++; Either undefined behaviour or statement has no effect.
You could threat that pointer as an unidimensional representation of a matrix. However I think it would be better to define string File_input::operator()(int row, int column)
If I do this, should I remove the *getfile and replace with getfile (same for return line)? I'm just unsure the best/correct method for getting back the multidimensional array data from within a class function.
To return a multidimensional array, that is, not a matrix object, declare it like this: int f(int x)[10][10];//f takes an integer and returns a pointer to a 10 by 10 array of ints.
This is because function calls and array indices have equal precedence, but they are left associative.
Whoops, nevermind, you can't. It's syntactically valid, but undefined semantically. Instead just return a matrix or a vector or something.
Actually you can, never mind again, here is the syntax step by step:
1 2 3 4 5 6
int i;//an integer
int i[10];//an array of integers
int i[10][10];//an array of arrays of ints
int (*i)[10][10];//a pointer to an array of arrays of ints. * has lower precedence than [].
int (*f(int))[10][10];/* a function returning a
pointer to an array of arrays of ints. () has higher precedence than *.*/
You could technically return a pointer to such a thing couldn't you? If you return a pointer to the first element you would have to do the pointer math yourself (which isn't that hard for a 2d array).
You could also use the array definitions the above poster used, though since he used a one letter function name and only gave a definition you might like to see what the fleshed out example would look like
int (*retarray(/*any argument variables would go in here*/))[10][10]{
...
return &var//assuming var is an int[10][10]
}
in case you don't know the /**/ i used above is a comment that blocks all contained text between the /* and the */ from being compiled as part of the code
Ok, I thought to try this using a vector, but I'm running into another problem. If this is a bad idea, I'll stick with my original. The problem I'm seeing is error: expected '{' before '(' token. I'm not sure where I'm going wrong here with vectors inside of a class as a function. Here is the class code changed to vector.
I want it to be a vector function within my class. I believe that line is incorrect, I just need to create a function with a multidimensional vector with everything below that line. I'm quite sure I'm going about this wrong...
I just created a normal vector function that will do this without having to be in a class. However, it would be nice to be able to add this to a class correctly. Anyone know of any links that explain using classes and vectors together?