Reputation: 3
I have created to call the constructor of MyClass, My class is defined as ref class Myclass sealed and this function is defined as static under public
IAsyncOperation<MyClass^>^ MyNameSpace::MyClass::CreateAsync()
{
return create_task(MyClass()).then([](MyClass^ objectx)
{
return ref new MyClass();
//return std::make_shared<MyClass>();
});
}
this is giving me bunch of errors like:
Error C2672 'Concurrency::details::declval': no matching overloaded function found
Error C2770 invalid explicit template argument(s) for '_Ty &&Concurrency::details::declval(void)'
Error C2672 'Concurrency::details::_FilterValidTaskType': no matching overloaded function found
Error C2672 'create_task': no matching overloaded function found
Upvotes: 0
Views: 161
Reputation: 12019
Your constructor is not an asynchronous operation so can't be used as a parameter to create_task
. If it takes a long time and you want to run the constructor as a task, use create_async
instead.
create_async
takes a function-like object (eg a lambda) and runs it as a task.
From your example above:
IAsyncOperation<MyClass^>^ MyNameSpace::MyClass::CreateAsync()
{
return concurrency::create_async([]
{
return ref new MyClass();
});
}
This will spin up a task to run the lambda (which constructs your class) and then wraps it in a WinRT IAsyncOperation<>
that you can use. Since your constructor doesn't do anything, I'm not sure why you want it to be asynchronous though (unless you omitted a bunch of expensive calls).
Upvotes: 1