Вероятно, я допускаю здесь какую-то элементарную ошибку, но гугл ничего не дал. Я использую 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
Ошибка C2440 Использование std::make_shared в Visual Studio ⇐ C++
Программы на C++. Форум разработчиков
-
Anonymous
1716437055
Anonymous
Вероятно, я допускаю здесь какую-то элементарную ошибку, но гугл ничего не дал. Я использую Visual Studio 2019, и мой код следующий:
#include
int main()
{
std::shared_ptr sp7 = std::make_shared(256, 2.0);
}
Я взял это прямо с https://en.cppreference.com/w/cpp/memory/shared_ptr/make_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 ==========
Подробнее здесь: [url]https://stackoverflow.com/questions/78520787/error-c2440-using-stdmake-shared-in-visual-studio[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия