Aillyn Aillyn - 3 months ago 10
C++ Question

Creating a set<char> in C++

I am coding this thing and it would be helpful to have a

static const set<char>
containing some elements that won't change.

class MyClass {
private:
static const set<char> mySet = ??
}


How can I do this? It would be nice if you could create them from a string, like
mySet("ABC")
, but I can't get the syntax to work.

Answer

Something like this will work just fine:

// my_class.h
class MyClass
{
  static const std::set<char> mySet;
};

// my_class.cpp
const char *tmp = "ABCDEFGHI";
const std::set<char> MyClass::mySet(tmp,tmp+strlen(tmp));