hi community,
my class uses the MultiMap function to calculate some values.
my idea was to define a 'new datatype' for the multimap.
that means a struct with 'size' filed and 'in' and 'out' arrays
i wanted to make this only available through the class.
so i defined this struct in the public area of the class definition:
// Class Definition:
class slight_Test {
public:
// public typedefs:
// variant 1
typedef struct {
byte size = 4;
word mm_In[4];
word mm_Out[4];
} tmultimap;
// variant 2
// struct sMultiMap {
// static const byte size;
// word mm_In[size];
// word mm_Out[size];
// };
// typedef struct sMultiMap tmultimap;
....
there are two variants.
both generates some errors if try to compile them and have used this type this way in my sketch:
slight_Test::tmultimap tmultimapMyTestMap = {
4,
{ 0, 100, 1000, 65535},
{ 0, 1, 200, 255}
};
variant 1 errors:
slight_Test_LibDev.ino: At global scope:
slight_Test_LibDev.ino:111: warning: missing braces around initializer for 'word [4]'
slight_Test_LibDev:111: error: braces around scalar initializer for type 'word'
if i uncomment the other version (variant 2) i get this errors:
In file included from slight_Test_LibDev.ino:104:
C:\...\arduino_sketchbook\libraries\slight_Test/slight_Test.h: At global scope:
C:\...\arduino_sketchbook\libraries\slight_Test/slight_Test.h:61: error: array bound is not an integer constant
C:\...\arduino_sketchbook\libraries\slight_Test/slight_Test.h:62: error: array bound is not an integer constant
i do not understand this error - size is defined as static and const ?! what other way to go?
variant2 is the think i really want to do.
is this the right way?
i think i could do something like this with an class definition and malloc in the constructor as i found in Pass array size to class constructor
but is it possible to declare a class in an class??
so is there a 'easy' way to do this just with structs or is there a other way?
i added an zip file with the test library / test class.
i also added the files separated so you just can open it for a short look without unpacking the zip.
this class does nothing useful..
its just for testing concepts..
i hope there is someone that can help me to learn some more about c++ concepts and how to do such things
sunny greetings
stefan
slight_Test.zip (11.1 KB)
slight_Test.h (4.75 KB)
slight_Test.cpp (10.1 KB)
slight_Test_LibDev.ino (23.9 KB)