How to simulate Func<T1, T2, TResult> in C++?
- by Zach
Hello all,
In C#, I use Func to replace Factories. For example:
class SqlDataFetcher
{
public Func<IConnection> CreateConnectionFunc;
public void DoRead()
{
IConnection conn = CreateConnectionFunc(); // call the Func to retrieve a connection
}
}
class Program
{
public void CreateConnection()
{
return new SqlConnection();
}
public void Main()
{
SqlDataFetcher f = new SqlDataFetcher();
f.CreateConnectionFunc = this.CreateConnection;
...
}
}
How can I simulate the code above in C++?