I'm having trouble with a class "Set" I try to use.
The Idea is to be able to access its properties from a public function in Set.
here is a minimal code sample:
#include <FastLED.h>
#define LEDTYPE WS2812B
#define PL 9 // LED pin
#define STRIP 134 //num LED in strip
#define GROUP_NUM 9
CRGB LED[STRIP];
void setup() {
delay(200);
FastLED.addLeds<LEDTYPE, PL, GRB>(LED, STRIP);
}
class Set {
public:
Set() {} //constructor
struct group {
byte red, green, blue;
};
struct set {
int setDelay;
group group[GROUP_NUM];
};
// void sets();
void GroupPlacement(set);
private:
// void groupPlacement(set);
};
Set set1;
set1.set.setDelay = 50;
set1.set.group[0] = (.100, .0, .0);
set1.group[1] = (0, 100, 0);
void Set::GroupPlacement(set thisset) {
thisset.group[0] = (1,2,3)
}
void loop() {
set1.GroupPlacement(set1)
}
I'm getting an error that invalid use of struct Set::set. But I initialised set1 of Type Set, what is the mistake here?
what is the correct way to access group[]? is it like I try with group[0] or group[1] (notice the dot)
error is: "error: no match for 'operator=' (operand types are 'Set::group' and 'int')"
The parameter type you’re trying to pass in the definition of GroupPlacement() doesn’t exist. Perhaps you meant “Set thisset”.
Regardless of the above, you’re passing by value which means ‘thisset’ is a local variable to GroupPlacement(). Any changes you make to it will have no effect to the argument when the function is called. You need to pass by pointer or reference.
wildbill:
You can use a struct in your class, but read reply #3 again. You defined a struct in your class, but you didn't declare an instance of that struct.