Detonator.h not compiling

So in my quest to develop multi_prop, I tested detonator.h as a single prop.

I got this compile error:


In file included from C:\Users\Olivier\Desktop\LightSabers\ProffieOS_7.14\config\olicomplex1.5.007_test_multi_prop.h:152,
                 from C:\Users\Olivier\Desktop\LightSabers\ProffieOS_7.14\ProffieOS_7.14.ino:522:
C:\Users\Olivier\Desktop\LightSabers\ProffieOS_7.14\props\detonator.h:17:3: error: non-static data member 'powered_' declared 'constexpr'
   17 |   constexpr bool powered_ = true;
      |   ^~~~~~~~~
Using library Wire at version 1.0 in folder: C:\Users\Olivier\AppData\Local\Arduino15\packages\proffieboard\hardware\stm32l4\3.6\libraries\Wire 
exit status 1
Error compiling for board Proffieboard V3.

ChatPGT told me to change from this (line 17):
constexpr bool powered_ = true;
to this:
static constexpr bool powered_ = true;
With the new line 17, it compiles but is it a “me” problem or does anyone of you get the same ?

Should I create a pull request for it or not ?

I think the better solution is to just remove ‘constexpr’.

If that compiles with static constexpr, thus meaning the variable is only ever read from… What’s the point of the variable? It doesn’t make much sense to me given the name of “powered”

EDIT: I see, it’s for conditional compilation. Is there a reason in that case not to make it static?

Maybe not.
It just seems less troublesome to male both sides of the #else behave more or less the same.

So which one is best for the detonator:
was

#ifdef DELAYED_OFF
  bool powered_ = false;
  void SetPower(bool on) { powered_ = on; }
#else
  constexpr bool powered_ = true;  //This line causes problem while compiling
  void SetPower(bool on) {}
#endif

And the options to change are:

#ifdef DELAYED_OFF
  bool powered_ = false;
  void SetPower(bool on) { powered_ = on; }
#else
  static constexpr bool powered_ = true;    // modded line
  void SetPower(bool on) {}
#endif

or

#ifdef DELAYED_OFF
  bool powered_ = false;
  void SetPower(bool on) { powered_ = on; }
#else
  bool powered_ = true;    // modded line
  void SetPower(bool on) {}
#endif

They both compile but I don’t know which is best ?

use this one

1 Like