ERR Message Help

I am trying to create an instance of a custom class inside of a structure, but I can't understand the error message i get when compiling. Maybe this is the wrong way of doing this. Thanks, Dave

Here is the Code for the Structure:

struct DATA_TO_SEND{
  char switches; // 00000000 - each bit = 1 switch
  Locomotion Loco(100, true);
}mydata;

Here is the error message: sketch_jun28a:14: error: expected identifier before numeric constant sketch_jun28a:14: error: expected ',' or '...' before numeric constant

Because of the open parenthesis the compiler thinks you are trying to declare a function named Loco that returns a value of type Locomotion. I don't know the proper syntax for declaring an initialized Locomotion object inside a structure declaration. Perhaps it can't be done. My first guess would be:

struct DATA_TO_SEND{
  char switches; // 00000000 - each bit = 1 switch
  Locomotion Loco;
} mydata = {0, Locomotion(100, true)};

It may, however, be necessary to declare Loco as a reference or pointer. If there is no default constructor or copy constructor for the Locomotion object there may be no way to create one to be initialized later.

No, the above will work just fine. The compiler will make a copy constructor for you, which is usually handy but sometimes annoying. Also note that the above doesn't actually use the default constructor, because when mydata is instantiated, it has values for Loco, so the fully-qualified constructor is called.

If you try this, you'll bump up against no default constructor

DATA_TO_SEND more_data;

You might also want to make switches unsigned - otherwise, bit 7 (the eight bit) is also the sign bit, which can make setting/getting values a bit annoying.