Вот моя «наивная» попытка:
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 | make_unique(_Args&&... __args)
| ^~~~~~~~~~~
/usr/lib/gcc/x86_64-pc-linux-gnu/13/include/g++-v13/bits/unique_ptr.h
../../libodbc/database_odbc.cpp
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 | make_unique(size_t __num)
| ^~~~~~~~~~~
/usr/lib/gcc/x86_64-pc-linux-gnu/13/include/g++-v13/bits/unique_ptr.h
../../libodbc/database_odbc.cpp
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 | make_unique(_Args&&...) = delete;
| ^~~~~~~~~~~
/usr/lib/gcc/x86_64-pc-linux-gnu/13/include/g++-v13/bits/unique_ptr.h
../../libodbc/database_odbc.cpp
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
Мобильная версия