xtd 0.2.0
Loading...
Searching...
No Matches
delegate.cpp

Shows how to use xtd::delegate class.

#include <xtd/console>
#include <xtd/delegate>
using namespace xtd;
void goodbye(const string& s) {
console::write_line("Goodbye {}", s);
}
class object {
public:
void hello(const string& s) {
console::write_line("Hello {}", s);
}
};
auto main() -> int {
using example_function = delegate<void(const string&)>;
auto instance = ::object {};
auto str = string {"World"};
//equivanet to : example_function f = {std::bind(&::object::hello, &instance, std::placeholders::_1)};
auto f = example_function {instance, &::object::hello};
// equivalent to : instance.hello(str)
f(str);
f = goodbye;
// equivalent to : goodbye(str)
f(str);
return 0;
}
// This code produces the following output :
//
// Hello, World
// Goodbye, World
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.h:42
@ f
The F key.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h:10