I've been doing a problem that involves rotating square arrays in c++. The length of the array is in 'len'. However, these rotate and flip methods return a 2d array and need 2d array arguments. The compiler gives me this error:
error: declaration of 'a' as multidimensional array must have bounds for all dimensions except the first.
However, the size of the array depends on the input - and when I have the input 'len' and declare the method, it gives me the old 'variable not declared in this scope' problem.
Pretty much, I can't say the length of the array because it changes depending on the input.
Is there any way to get past this?
#include <iostream>
#include <fstream>
#include <cmath>
using namespace std;
class transform{
private:
int len;
public:
bool rot90[][](bool a[][]);
bool rot180[][] (bool a[][]);
bool check (bool a[][], bool b[][]);
bool rot270[][] (bool a[][]);
bool flip[][] (bool a[][]);
};
bool transform::check(bool a[len][len], bool b[len][len]){
for(int h=0; h<len; h++){
for(int w=0; w<len; w++){
if(a[h][w] != b[h][w])
return false;
}
}
return true;
}
bool transform::rot90[len][len] (bool a[len][len]){
bool[len][len] b;
for(int h=0; h<len; h++){
for(int w<0; w<len; w++){
b[w][len-1-h] = a[h][w];
}
}
return b;
}
bool transform::rot270[len][len] (bool a[len][len]){
bool[len][len] b;
for(int h=0; h<len; h++){
for(int w<0; w<len; w++){
b[len-1-w][h] = a[h][w];
}
}
return b;
}
bool transform::flip[len][len] (bool a[len][len]){
bool[len][len] b;
for(int h=0; h<len; h++){
for(int w<0; w<len; w++){
b[h][len-1-w] = a[h][w];
}
}
return b;
}
... code continues