静态类中的向量

alv*_*e89 0 c++ arduino

我想在静态类中有一个静态(常量)向量。向量不会填充新元素,它只会包含在 class configuration: 中定义的元素{1,2,3,4,5}

我怎样才能使向量debugLevels静态?

#include <ArduinoSTL.h>

class configuration {
  public:
  static std::vector<int> const debugLevels = {1,2,3,4,5}; // throws error: in-class initialization of static data member 'const std::vector<int> configuration::debugLevels' of incomplete type
};

void setup() {
  for(int i=0; i<configuration::debugLevels.size(); i++ {
    // do some stuff here...
  }
}

void loop() {
}
Run Code Online (Sandbox Code Playgroud)

Nat*_*ica 5

最简单的方法就是把你classnamespace

namespace configuration {
  const std::vector<int> debugLevels = {1,2,3,4,5};
}
Run Code Online (Sandbox Code Playgroud)