define size of array in constructor
hi,
i want make library 1 of sketches (dycoled). works fine now, have problem.
at moment use constant ledcount set size of arrays , loops in functions. when change it, works pretty good. here comes problem library.
the size of arrays should dynamic, therefore lib should count of used leds in init method. late change size of array.
example (not in code):
a normal variable can changed @ time, size of arry must set right @ declaration, not later. fact makes difficult set size of arrays in .cpp or .h file lib, because don't know count of used leds @ time.
is there method (or workaround) solve problem?
i imagine one. generate array of objects lib. there copies of functions use, , mess, too.
correct me if i'm wrong
greets
i want make library 1 of sketches (dycoled). works fine now, have problem.
quote
#include "dycoled_t.h"
/*
dycoled library, designed for usi inferface
on atmega85.
*/
// will be set in constucor (?)
const int ledcount = 3;
//...
// custom array which holds the color information
dycoled_t dycoled[ledcount];
// word array for the messages for the leds
byte ledmessagemsb_a[ledcount];
byte ledmessagelsb_a[ledcount];
// check if leds are already initialized
boolean isinit = 0;
//..........
at moment use constant ledcount set size of arrays , loops in functions. when change it, works pretty good. here comes problem library.
the size of arrays should dynamic, therefore lib should count of used leds in init method. late change size of array.
example (not in code):
code: [select]
int ledpin; // value can changed @ time
int anynumber[]; //not valid without values or size
a normal variable can changed @ time, size of arry must set right @ declaration, not later. fact makes difficult set size of arrays in .cpp or .h file lib, because don't know count of used leds @ time.
is there method (or workaround) solve problem?
i imagine one. generate array of objects lib. there copies of functions use, , mess, too.
correct me if i'm wrong

greets
see ideas:
http://arduino.cc/forum/index.php/topic,104334.0.html
http://arduino.cc/forum/index.php/topic,104334.0.html
Arduino Forum > Using Arduino > Programming Questions > define size of array in constructor
arduino
Comments
Post a Comment