Вот моя «наивная» попытка:
Код: Выделить всё
std::unique_ptr ptr;
ptr = std::make_unique( "INSERT INTO mytable VALUES();" );
Код: Выделить всё
1> c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\memory(2539): error C2440: 'initializing': cannot convert from 'const char [380]' to '_Ty'
1> with
1> [
1> _Ty=SQLWCHAR
1> ]
1> c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\memory(2539): note: There is no context in which this conversion is possible
РЕДАКТИРОВАТЬ:
Я пытался построить следующее в Linux с unixODBC и получил следующее:
Код:
Код: Выделить всё
std::unique_ptr ptr;
ptr = std::make_unique( L"INSERT INTO mytable VALUES();" );
Код: Выделить всё
error: no matching function for call to 'make_unique(const wchar_t [23])'
In file included from /usr/lib/gcc/x86_64-pc-linux-gnu/13/include/g++-v13/memory:78,
from ../../libodbc/database_odbc.cpp:20:
/usr/lib/gcc/x86_64-pc-linux-gnu/13/include/g++-v13/bits/unique_ptr.h:1069:5: note: candidate: 'template std::__detail::__unique_ptr_t std::make_unique(_Args&& ...)'
1069 | make_unique(_Args&&... __args)
| ^~~~~~~~~~~
/usr/lib/gcc/x86_64-pc-linux-gnu/13/include/g++-v13/bits/unique_ptr.h:1069:5: note: template argument deduction/substitution failed:
../../libodbc/database_odbc.cpp:2275:31: note: couldn't deduce template parameter '_Tp'
2275 | ptr = std::make_unique( L"INSERT INTO abcattbl ;" );
| ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/lib/gcc/x86_64-pc-linux-gnu/13/include/g++-v13/bits/unique_ptr.h:1084:5: note: candidate: 'template std::__detail::__unique_ptr_array_t std::make_unique(size_t)'
1084 | make_unique(size_t __num)
| ^~~~~~~~~~~
/usr/lib/gcc/x86_64-pc-linux-gnu/13/include/g++-v13/bits/unique_ptr.h:1084:5: note: template argument deduction/substitution failed:
../../libodbc/database_odbc.cpp:2275:31: note: couldn't deduce template parameter '_Tp'
2275 | ptr = std::make_unique( L"INSERT INTO abcattbl ;" );
| ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/lib/gcc/x86_64-pc-linux-gnu/13/include/g++-v13/bits/unique_ptr.h:1094:5: note: candidate: 'template std::__detail::__invalid_make_unique_t std::make_unique(_Args&& ...)' (deleted)
1094 | make_unique(_Args&&...) = delete;
| ^~~~~~~~~~~
/usr/lib/gcc/x86_64-pc-linux-gnu/13/include/g++-v13/bits/unique_ptr.h:1094:5: note: template argument deduction/substitution failed:
../../libodbc/database_odbc.cpp:2275:31: note: couldn't deduce template parameter '_Tp'
2275 | ptr = std::make_unique( L"INSERT INTO abcattbl ;" );
| ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
make[2]: *** [Makefile:531: libodbc_lib_la-database_odbc.lo] Error 1
make[2]: Leaving directory '/home/igor/dbhandler/Debug/libodbc'
make[1]: *** [Makefile:526: all-recursive] Error 1
make[1]: Leaving directory '/home/igor/dbhandler/Debug'
make: *** [Makefile:437: all] Error 2
ПОСКОЛЬКУ ВОПРОС НЕПРАВИЛЬНО ЗАКРЫТ, Я ЗАКРЫТ ЭТО, РЕДАКТИРОВАНИЕ ОП...
Я занимаюсь рефакторингом кода, поэтому сейчас мне не нужен умный указатель. Код выглядит намного лучше и его удобно поддерживать
Я просто подумал, что кто-нибудь поможет мне разобраться в умных указателях, но, к сожалению, это не так.
Извините за шум...
Подробнее здесь: https://stackoverflow.com/questions/793 ... -unque-ptr
Мобильная версия