1

In C++ we have class member initializers, yet I cannot seem to use auto/static type deduction for non-static members.

struct Foo {
    auto bar = []() { return 1; };
    auto baz = "test";
};

That won't work (at least on clang: Apple LLVM version 4.2 (clang-425.0.24)).

Is this just a compiler bug, or does the standard not require this to be supported (and if so, why can't it be)?

Xeo
  • 129,499
  • 52
  • 291
  • 397
mmocny
  • 8,775
  • 7
  • 40
  • 50
  • You are right, thanks (I did search, not sure how I missed this!) closing. – mmocny Mar 06 '13 at 00:09
  • Note that for the first case, an [std::function](http://en.cppreference.com/w/cpp/utility/functional/function) would work (on the off-chance that was your motivation for the question). – Jamin Grey Mar 06 '13 at 00:26
  • That was my motivation for the question, and you are right, using std::function does work. I wanted to compare using std::function to using lambda's type directly, which is how this problem arose. – mmocny Mar 06 '13 at 00:37

0 Answers0