Setting struct in a public constant of a class

So, I'm trying to create a class that would basically hold all my configuration parameters, and I want to use structs to hold data for more complicated things that have multiple parameters. Here's the code I have so far at the top of the sketch, before setup() and loop() methods:

struct TurnPins {
  int In;
  int Out;
};

class Pinout {
    public: 
      static int const PhotoSens = A3;
      static const TurnPins TurnOne[] = {5,6};
};

When I try to compile, I get an error: "a brace-enclosed initializer is not allowed here before '{' token." When I remove my TurnOne constant outside of the Pinout class, everything compiles without an error. I tried googling, as well as searching on Arduino forums, but does not seem like I can find how to make it work. And also it looks like I'm doing something other people are not.

So I have one of the two questions, really :slight_smile: How to make this work? Or what is the best way to have configuration like that at the top of your file, and have convenient access in the code (like digitalRead(Pinout::TurnOne::In))?

Thanks!

I’m not sure what the point of your class is, if it only has static members, however this compiles:

struct TurnPins {
  int In;
  int Out;
};

class Pinout {
    public: 
      static int const PhotoSens = A3;
      static const TurnPins TurnOne[2];
};

const TurnPins Pinout::TurnOne [2] = { {5, 6}, {7, 8} };

void setup ()
  {
  Serial.begin (115200);
  for (int i = 0; i < 2; i++)
    {
    Serial.println (Pinout::TurnOne [i].In);
    Serial.println (Pinout::TurnOne [i].Out);
    }
  }  // end of setup

void loop () { }

Output:

5
6
7
8

I'm not sure you know what you're doing or even think you know what you're doing, and even if you do you haven't communicated your intentions or how you plan to use this class so that we can properly assist.

When I try to compile, I get an error: "a brace-enclosed initializer is not allowed here before '{' token."

Sure, because you can't initialize class members in a header file. You can ONLY do that in the source file, in some member method.

I'm trying to have all my configuration (like pin-outs, thresholds, etc) in one place. How can I achieve this? Of course, I can just put a bunch of defines, and have really long variable names, but something more conforming to good coding practices and has better readability/usability would be what I'm after.

And yes, I don't know what I'm doing, as most of my experience is with scripting languages, which lack many rigorous restrictions C++ has.

How about a little more concrete example of something you plan on doing as a starting point around which to base an answer around.

sergesyrota:
I'm trying to have all my configuration (like pin-outs, thresholds, etc) in one place. How can I achieve this? Of course, I can just put a bunch of defines, and have really long variable names, but something more conforming to good coding practices and has better readability/usability would be what I'm after.

And yes, I don't know what I'm doing, as most of my experience is with scripting languages, which lack many rigorous restrictions C++ has.

You could make enums. You can also make namespaces.