Unque_ptr wird initialisiert [Duplikat]C++

Programme in C++. Entwicklerforum
Guest
 Unque_ptr wird initialisiert [Duplikat]

Post by Guest »

ALLE,
Hier ist mein „naiver“ Versuch:

Code: Select all

std::unique_ptr ptr;
ptr = std::make_unique( "INSERT INTO mytable VALUES();" );
was zu einem Kompilierungsfehler führt.

Code: Select all

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
Wie kann man es richtig initialisieren?
BEARBEITEN:
Ich habe versucht zu bauen Folgendes unter Linux mit unixODBC und habe Folgendes erhalten:
Code:

Code: Select all

std::unique_ptr ptr;
ptr = std::make_unique( L"INSERT INTO mytable VALUES();" );
Die Fehler sind:

Code: Select all

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
EDIT2:
DAS DIE FRAGE FALSCH GESCHLOSSEN IST, SCHLIEßE ICH DIES, INDEM ICH EINE OP BEARBEITE...
Ich überarbeite den Code und benötige daher im Moment keinen Smart Pointer. Der Code sieht viel besser aus und ist besser wartbar.
Ich dachte nur, dass mir jemand helfen könnte, Smart Pointer zu verstehen, aber leider ist das nicht der Fall.
Entschuldigung für den Lärm...

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post