test of function object as default parameter.
// test of function object as default parameter.
// c++ -Wall -std=c++11 ./funcobj_param_test.cpp -o funcobj_param_test
//
// $ ./funcobj_param_test
// call func
// call callback func
// arg1: str1
// arg2: str2
// call func
#include <iostream>
#include <functional>
#include <string>
// typedef
using cbfunc_t = std::function<void(std::string arg1, std::string arg2)>;
void func(cbfunc_t cb = [](std::string msg, std::string str2) {}) {
std::string str1("str1");
std::string str2("str2");
std::cout << "call func" << std::endl;
cb(str1, str2);
}
int main() {
func([](std::string arg1, std::string arg2){
std::cout << "call callback func" << std::endl;
std::cout << "arg1: " << arg1 << std::endl;
std::cout << "arg2: " << arg2 << std::endl;
});
// use default parameters
func();
return 0;
}