#include <functional>
#include <iostream>
#include <string>

struct functor_with_string_data
{
    std::string s ;

    functor_with_string_data( const std::string & str ) : s(str) {}

    void operator()() { std::cout << s << '\n' ; }
};

struct functor_with_int_data
{
    int data ;

    functor_with_int_data( int num ) : data(num) {}

    void operator()() {std::cout << data << '\n' ;}
};


class myclass
{
public:
    myclass( std::function<void()> f = nullptr ) : _func(f) {}
    void setCallback( std::function<void()> f ) { _func = f ; }

    void doCallback() const { _func(); }


private:
    std::function<void()> _func ;
};

int main()
{
    myclass obj ;

    obj.setCallback(functor_with_string_data("Hello, world!")) ;
    obj.doCallback() ;

    obj.setCallback(functor_with_int_data(42)) ;
    obj.doCallback() ;
}