lundi 27 juillet 2015

Attempting to use vector's fill constructor in class member initialization fails. What is wrong?

When using std::vector's fill constructor (either form) with C++11's class member initialization feature, the following code fails to compile (under clang/llvm 3.6):

#include <vector>

class Foo
{
  std::vector<char> buf_(10); //compiler error!
  std::vector<std::vector<char>> buf2_(10, std::vector<char>(20)); //compiler error!

public:
  void Bar();
};

void Foo::Bar()
{
  std::vector<char> buf3_(10); //OK
  std::vector<std::vector<char>> buf4_(10, std::vector<char>(20));  //OK
}

I've searched for issues around vector fill constructors and class member initialization, but have come up empty. Any idea what am I missing?

Aucun commentaire:

Enregistrer un commentaire