Reputation: 85
I'm new in UWP and c++ too. I'm trying to write a simple app that handles http-api. My example:
void ForecastFromMSW::MainPage::GetTheCity(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
String ^mystr = "http://google.com"; // creating a string object
Uri url(mystr); // crating an url object
HttpClient cli; //creating an object of HttpClient
cli.GetAsync(url); // pass url object to cli
}
a message from compiler:
1>------ Build started: Project: ForecastFromMSW, Configuration: Debug Win32 ------
1> MainPage.xaml.cpp
1>c:\users\9maf4you\documents\visual studio 2015\projects\forecastfrommsw\forecastfrommsw\mainpage.xaml.cpp(38): error C2664: 'Windows::Foundation::IAsyncOperationWithProgress<Windows::Web::Http::HttpResponseMessage ^,Windows::Web::Http::HttpProgress> ^Windows::Web::Http::HttpClient::GetAsync(Windows::Foundation::Uri ^,Windows::Web::Http::HttpCompletionOption)': cannot convert argument 1 from 'Windows::Foundation::Uri' to 'Windows::Foundation::Uri ^'
1> c:\users\9maf4you\documents\visual studio 2015\projects\forecastfrommsw\forecastfrommsw\mainpage.xaml.cpp(38): note: No user-defined-conversion operator available, or
1> c:\users\9maf4you\documents\visual studio 2015\projects\forecastfrommsw\forecastfrommsw\mainpage.xaml.cpp(38): note: No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
========== Deploy: 0 succeeded, 0 failed, 0 skipped ==========
I see, that compiler can't convert one type to another and I understand I have to pass ^Uri to GetAsync. But I don't know what I should do. Thnx.
Upvotes: -3
Views: 473
Reputation: 51506
In C++/CX, objects are usually instantiated using ref new, returning a ref-counted object handle. The easiest way to fix your code would be to replace
Uri url(mystr);
with
Uri^ url = ref new Uri(mystr);
The compiler will generate code to decrement the ref-count on url
when it goes out of scope; the object is automatically destroyed when the reference count reaches zero.
Upvotes: 3