-
Notifications
You must be signed in to change notification settings - Fork 0
/
InterfaceVersion4.h
35 lines (29 loc) · 976 Bytes
/
InterfaceVersion4.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#ifndef INTERFACEVERSION4_H
#define INTERFACEVERSION4_H
#include <functional>
#include <iostream>
#include <memory>
using MyFuncRead = std::function<long(void)>;
using MyFuncWrite = std::function<void(const long)>;
class BaseLambda
{
public:
long read() { return m_readFunc(); }
void write(const long value) { m_writeFunc(value); }
protected:
BaseLambda(MyFuncRead readFunc, MyFuncWrite writeFunc) : m_readFunc(readFunc), m_writeFunc(writeFunc) {}
MyFuncRead m_readFunc;
MyFuncWrite m_writeFunc;
};
class ChildLambda : public BaseLambda
{
public:
ChildLambda()
: BaseLambda([]() { return ChildLambda::read_impl(); },
[](const long value) { ChildLambda::write_impl(value); })
{}
private:
static long read_impl() { return 253 * 324; /*std::cout << "Child::read\n";*/ }
static void write_impl(const long value) { std::cout << "Child::write " << value << std::endl; }
};
#endif // INTERFACEVERSION4_H