Trying to derive a class from std::function
, and for starters inherit the constructors. This is what I guessed at:
#include <iostream>
#include <functional>
using namespace std;
template< class R, class... Args >
class MyFunction : public std::function<R(Args...)> {
public:
using std::function<R(Args...)>::function;
};
int main() {
std::function<void()> f_display_42 = []() { std::cout << 42; }; //works
MyFunction<void()> mine = []() { std::cout << 42; }; //errors
}
Errors that come back are:
prog.cpp: In instantiation of ‘class MyFunction<void()>’:
prog.cpp:14:24: required from here
prog.cpp:6:7: error: function returning a function
class MyFunction : public std::function<R(Args...)> {
^
prog.cpp:8:38: error: function returning a function
using std::function<R(Args...)>::function;
^
prog.cpp:8:38: error: using-declaration for non-member at class scope
prog.cpp: In function ‘int main()’:
prog.cpp:14:55: error: conversion from ‘main()::__lambda1’
to non-scalar type ‘MyFunction<void()>’ requested
MyFunction<void()> mine = []() { std::cout << 42; };
In GCC 4.8.2.