- Solution

This lesson contains the solution to the exercise in the previous lesson.

We'll cover the following...

Solution #

Press + to interact
#include <functional>
#include <string>
#include <iostream>
std::function<std::string()> makeLambda() {
const std::string val = "on stack created";
return [val]{return val;};
}
int main(){
std::cout << std::endl;
auto bad = makeLambda();
std::cout << bad() << std::endl;
std::cout << std::endl;
}

Explanation

...