#include "callback_function.hpp"
#include <string>
#include <iostream>
#include <functional>
class MyClass
{
public:
static void mystaticfunction(std::string str)
{
std::cout << str << std::endl;
}
void mymemberfunction(std::string str)
{
mystaticfunction(str);
}
};
void test(std::string str, std::function<void(std::string)> callBack = nullptr)
{
if (callBack)
{
callBack(str);
}
}
void use_callback_function(std::string output)
{
// Sample 1.
test(output, MyClass::mystaticfunction);
// Sample 2.
MyClass myClass;
auto callBack = [&myClass](std::string str)
{
myClass.mymemberfunction(str);
};
test(output, callBack);
}