C++Guns – RoboBlog

29.07.2015

DerivedFunctor - fancy

Filed under: Allgemein — Tags: — Thomas @ 22:07

In C++11 kann man von einer Funktion erben. Krass.
Lambdas sind krass.
Das typedef musste sein, sonst hat er nicht compiliert. Ist vllt aber
nur ein Compilerbug und bald nicht mehr nötig.

auto foo = [](){return 42;};

class DerivedFunctor : public decltype(foo)
{
  typedef decltype(foo) type;
  public:
    DerivedFunctor(type foo)
    : type(foo)
    {
    }

    auto operator()() {
      cout << "DerivedFunctor::operator()\n";
      return type::operator()();
    }
};

int main() {
  DerivedFunctor t(foo);
  cout << t();
}

No Comments

No comments yet.

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.

Powered by WordPress