Ошибка C2440 Использование std::make_shared в Visual StudioC++

Программы на C++. Форум разработчиков
Ответить
Anonymous
 Ошибка C2440 Использование std::make_shared в Visual Studio

Сообщение Anonymous »

Вероятно, я допускаю здесь какую-то элементарную ошибку, но гугл ничего не дал. Я использую Visual Studio 2019, и мой код следующий:
#include

int main()
{
std::shared_ptr sp7 = std::make_shared(256, 2.0);
}

Я взял это прямо с https://en.cppreference.com/w/cpp/memor ... ake_shared, поэтому у меня есть основания полагать, что это правильно. Тем не менее, когда я компилирую, я получаю
Error C2440 '=': cannot convert from '_Ux (*const )' to 'double *'

Двойной щелчок по этой ошибке приводит меня к некоему шаблону функции под названием _Set_ptr_rep_and_enable_shared, который мало что мне говорит. Полный результат сборки:
Build started...
1>------ Build started: Project: Mem, Configuration: Debug Win32 ------
1>Mem.cpp
1>C:\[MSVCdir]\include\xmemory(1893,9): warning C4200: nonstandard extension used: zero-sized array in struct/union
1>C:\[MSVCdir]\include\xmemory(1893,9): message : This member will be ignored by a defaulted constructor or copy/move assignment operator
1>C:\[MSVCdir]\include\memory(2027): message : see reference to class template instantiation 'std::_Wrap' being compiled
1> with
1> [
1> _Ty=double []
1> ]
1>C:\[MSVCdir]\include\memory(2725): message : see reference to class template instantiation 'std::_Ref_count_obj2' being compiled
1> with
1> [
1> _Ty=double []
1> ]
1>C:\[localdir]\Test\Mem\Mem.cpp(5): message : see reference to function template instantiation 'std::shared_ptr std::make_shared(int &&,double &&)' being compiled
1>C:\[MSVCdir]\include\memory(1770,1): error C2440: '=': cannot convert from '_Ux (*const )' to 'double *'
1> with
1> [
1> _Ux=double []
1> ]
1>C:\[MSVCdir]\include\memory(1770,22): message : Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>C:\[MSVCdir]\include\memory(2725): message : see reference to function template instantiation 'void std::shared_ptr::_Set_ptr_rep_and_enable_shared(_Ux (*const ),std::_Ref_count_base *const ) noexcept' being compiled
1> with
1> [
1> _Ty=double [],
1> _Ux=double []
1> ]
1>C:\[MSVCdir]\include\memory(2728): message : see reference to function template instantiation 'void std::shared_ptr::_Set_ptr_rep_and_enable_shared(_Ux (*const ),std::_Ref_count_base *const ) noexcept' being compiled
1> with
1> [
1> _Ty=double [],
1> _Ux=double []
1> ]
1>C:\[localdir]\Test\Mem\Mem.cpp(5): message : see reference to function template instantiation 'std::shared_ptr std::make_shared(int &&,double &&)' being compiled
1>Done building project "Mem.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


Подробнее здесь: https://stackoverflow.com/questions/785 ... ual-studio
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C++»