2D ARRAY WITH A CLASS
i beginner on uno , programming on 1.5.6. have question how can manipulate 2d array without making 2d array(in interest of space). have tried using class, example below, upside leaves me lot more space, , code runs faster.
the issue comes fact cannot make variable number of these objects, have know number of "4's" needed. there anyway can work around this, va_list or need approach.
code: [select]
class enter{
private:
int right;
int left;
public:
enter(){
}
enter(int y,int x){
right=y;
left=x;
}
int getright(){
return right;
}
int getleft(){
return left;
}
boolean check(int y,int x){
if(right==y&&left==x){
return true;
}
else{
return false;
}
}
};
void setup() {
serial.begin(9600); // put setup code here, run once:
}
void loop() {
for (int p = 0; p < 10; p++) {
for (int = 0; < 15; i++) {
// client.print(array[p][i]);
// client.print("|");
serial.print("0");
serial.print("|");
}
//client.println("<br />");
serial.println();
}
serial.println("break");
enter b(2,3);
for (int p = 0; p < 10; p++) {
for (int = 0; < 15; i++) {
// client.print(array[p][i]);
// client.print("|");
if(b.check(p,i)){
serial.print("4");
serial.print("|");
}
else{
serial.print("0");
serial.print("|");
}
}
//client.println("<br />");
serial.println();
}
serial.println("done");
}
the issue comes fact cannot make variable number of these objects, have know number of "4's" needed. there anyway can work around this, va_list or need approach.
quote
i have question how can manipulate 2d array without making 2d array
i've got news you. can't manipulate didn't make.
quote
the issue comes fact cannot make variable number of these objects
a variable number of objects? instances of enter class?
of course can create variable number of them. can't do, without using malloc() or new() create variable length array of them.
Arduino Forum > Using Arduino > Programming Questions > 2D ARRAY WITH A CLASS
arduino
Comments
Post a Comment