I am new to VC++ 2012. I have this code snippet.
auto it = query_map.find(U("callback"));
The problem is right under the dot there is a red line the error is
Error 1 error C2664: 'std::_Tree_iterator std::_Tree::find(const http::uri::encoded_string &)' : cannot convert parameter 1 from 'const wchar_t [9]' to 'const http::uri::encoded_string &' d:\maverick\projects\strikeforce\src\server\server\server.cpp 26
Can someone tell me a solution to this error?
Error 1 error C2664: 'std::_Tree_iterator std::_Tree::find(const http::uri::encoded_string &)'
This is a problem with the method find() from the class std::Tree
cannot convert parameter 1 from 'const wchar_t [9]' to 'const http::uri::encoded_string &'
The find() method must be used with a paremeter of type 'const http::uri::encoded_string &', but you passed a 'const wchar_t [9]'.
the method U() you have used returns an array of chars, but the find() method need another type of object.
Related
I m trying to build Petsc Complex Version on windows.(VS2019 and c++17)
the configuration is as bellow :
./configure --with-cc="win32fe cl" --with-cxx="win32fe cl" --with-fc=0 --download-f2cblaslapack --with-memalign=64 --with-mpi-include=/cygdrive/c/software/Mpich2/Include --with-mpi-lib=/cygdrive/c/software/Mpich2/lib/mpi.lib --with-mpi-mpiexec=/cygdrive/c/software/Mpich2/bin/mpiexec.exe CFLAGS="-MD -wd4996" CXXFLAGS="-MD -wd4996" COPTFLAGS="-O2" CXXOPTFLAGS="-O2" --with-debugging=0 --with-scalar-type=complex --with-clanguage=cxx
when I try to make the configuration an error appear :
CXX arch-mswin-cxx-opt/obj/vec/is/sf/impls/basic/sfpack.o
sfpack.c
C:\software\PETSC-~1.4\src\vec\is\sf\impls\basic\sfpack.c(977): error C2664: 'int MPI_Reduce_local(void *,void *,int,MPI_Datatype,MPI_Op)': cannot convert argument 1 from 'const char *' to 'void *'
C:\software\PETSC-~1.4\src\vec\is\sf\impls\basic\sfpack.c(977): note: Conversion loses qualifiers
C:\software\Mpich2\Include\mpi.h(887): note: see declaration of 'MPI_Reduce_local'
C:\software\PETSC-~1.4\src\vec\is\sf\impls\basic\sfpack.c(980): error C2664: 'int MPI_Reduce_local(void *,void *,int,MPI_Datatype,MPI_Op)': cannot convert argument 1 from 'const void *' to 'void *'
C:\software\PETSC-~1.4\src\vec\is\sf\impls\basic\sfpack.c(980): note: Conversion loses qualifiers
C:\software\Mpich2\Include\mpi.h(887): note: see declaration of 'MPI_Reduce_local'
C:\software\PETSC-~1.4\src\vec\is\sf\impls\basic\sfpack.c(1001): error C2664: 'int MPI_Reduce_local(void *,void *,int,MPI_Datatype,MPI_Op)': cannot convert argument 1 from 'const char *' to 'void *'
C:\software\PETSC-~1.4\src\vec\is\sf\impls\basic\sfpack.c(1001): note: Conversion loses qualifiers
C:\software\Mpich2\Include\mpi.h(887): note: see declaration of 'MPI_Reduce_local'
make[3]: *** [gmakefile:184: arch-mswin-cxx-opt/obj/vec/is/sf/impls/basic/sfpack.o] Error 2
make[2]: *** [/cygdrive/c/software/petsc-3.13.4/lib/petsc/conf/rules:50: libs] Error 2
**************************ERROR*************************************
Error during compile, check arch-mswin-cxx-opt/lib/petsc/conf/make.log
Send it and arch-mswin-cxx-opt/lib/petsc/conf/configure.log to petsc-maint#mcs.anl.gov
********************************************************************
For the Real Version there is no issue !!! please Any help
I have strange error when compiling open source lib
I using visual studio 2019
and I created a solution to the lib cmake -G "Visual Studio 16 2019" ../"
but I keep getting erros when compiling :
starting with this line :
CFUNC char *optarg = "";
C:\Dev\my\cpp\libs\libunistd-master\unistd\getopt.cpp(16,24): error C2440: 'initializing': cannot convert from 'const char [1]' to 'char *'
1>C:\Dev\my\cpp\libs\libunistd-master\unistd\getopt.cpp(16,20): message : Conversion from string literal loses const qualifier (see /Zc:strictStrings)
1>C:\Dev\my\cpp\libs\libunistd-master\unistd\getopt.cpp(30,27): error C2440: 'initializing': cannot convert from 'const char [1]' to 'char *'
1>C:\Dev\my\cpp\libs\libunistd-master\unistd\getopt.cpp(30,21): message : Conversion from string literal loses const qualifier (see /Zc:strictStrings)
1>C:\Dev\my\cpp\libs\libunistd-master\unistd\getopt.cpp(38,16): error C2440: '=': cannot convert from 'const char [1]' to 'char *'
1>C:\Dev\my\cpp\libs\libunistd-master\unistd\getopt.cpp(38,12): message : Conversion from string literal loses const qualifier (see /Zc:strictStrings)
1>C:\Dev\my\cpp\libs\libunistd-master\unistd\getopt.cpp(45,16): error C2440: '=': cannot convert from 'const char [1]' to 'char *'
1>C:\Dev\my\cpp\libs\libunistd-master\unistd\getopt.cpp(45,12): message : Conversion from string literal loses const qualifier (see /Zc:strictStrings)
1>C:\Dev\my\cpp\libs\libunistd-master\unistd\getopt.cpp(51,16): error C2440: '=': cannot convert from 'const char [1]' to 'char *'
1>C:\Dev\my\cpp\libs\libunistd-master\unistd\getopt.cpp(51,12): message : Conversion from string literal loses const qualifier (see /Zc:strictStrings)
1>C:\Dev\my\cpp\libs\libunistd-master\unistd\getopt.cpp(85,16): error C2440: '=': cannot convert from 'const char [1]' to 'char *'
1>C:\Dev\my\cpp\libs\libunistd-master\unistd\getopt.cpp(85,12): message : Conversion from string literal loses const qualifier (see /Zc:strictStrings)
1>C:\Dev\my\cpp\libs\libunistd-master\unistd\getopt.cpp(94,15): error C2440: '=': cannot convert from 'const char [1]' to 'char *'
1>C:\Dev\my\cpp\libs\libunistd-master\unistd\getopt.cpp(94,11): message : Conversion from string literal loses const qualifier (see /Zc:strictStrings)
"" is a constant string. You can't just assign that to a non-constant char *, because then it could be mutated through the pointer.
According to the source code of libunistd, the implementation was taken from NetBSD, but a quick check¹ shows that NetBSD doesn't initialize optarg at all:
char *optarg; /* argument associated with option */
You could follow the same approach.
You could also turn off this error by passing /Zc:strictStrings- (note the hyphen) to your compiler. As long as the constant string isn't written to, there should be little harm in that.
You might want to report this as a bug to the library author.
¹ Not sure I'm looking at the latest version. It's from 2014.
It's not strange. The type of "" (or any string literal) is const char[] and the type of optarg is char*. So if the assignment was allowed you would be able to modify a string literal via the pointer optarg. Clearly that's not desireable.
In an older version of C++, this assignment was allowed as a special case, simply because there was too much old C code that did this. But this is no longer the case.
I'm still rather new to C++ but I've ran into a problem I can't solve, this is my error message:
'HMODULE GetModuleHandleW(LPCWSTR)': cannot convert argument 1 from 'const char *' to 'LPCWSTR'
And this the line that is throwing the error:
ModuleHandle = (DWORD)GetModuleHandle(moduleName.c_str());
You are passing a char * to something that needs a wchar_t *. You'll have to either convert your stringtype to wchar_t *, for example using the MultiByteToWideChar function (https://msdn.microsoft.com/en-us/library/windows/desktop/dd319072%28v=vs.85%29.aspx), or you can use the non-wide version of GetModuleHandle by calling GetModuleHandleA() instead of GetModuleHandleW().
I have added sqlite3.c file into my project.
And #include. Here is the code:
#include <sqlite3.h>
using namespace std;
int main()
{
return 0;
}
I compile the program and it throws the following error:
1>..\..\..\..\..\..\..\libraries\sqlite-amalgamation-3080702\sqlite3.c(15705): error C2440: '=' : cannot convert from 'void *' to 'char *'
1> Conversion from 'void*' to pointer to non-'void' requires an explicit cast
1>..\..\..\..\..\..\..\libraries\sqlite-amalgamation-3080702\sqlite3.c(19741): error C2440: '=' : cannot convert from 'void *' to 'sqlite3_mutex *'
1> Conversion from 'void*' to pointer to non-'void' requires an explicit cast
1>..\..\..\..\..\..\..\libraries\sqlite-amalgamation-3080702\sqlite3.c(20665): error C2440: '=' : cannot convert from 'void *' to 'char *'
1> Conversion from 'void*' to pointer to non-'void' requires an explicit cast
1>..\..\..\..\..\..\..\libraries\sqlite-amalgamation-3080702\sqlite3.c(20677): error C2440: '=' : cannot convert from 'void *' to 'char *'
1> Conversion from 'void*' to pointer to non-'void' requires an explicit cast
1>..\..\..\..\..\..\..\libraries\sqlite-amalgamation-3080702\sqlite3.c(21142): error C2440: '=' : cannot convert from 'void *' to 'char *'
1> Conversion from 'void*' to pointer to non-'void' requires an explicit cast
1>..\..\..\..\..\..\..\libraries\sqlite-amalgamation-3080702\sqlite3.c(21256): error C2440: '=' : cannot convert from 'void *' to 'char *'
1> Conversion from 'void*' to pointer to non-'void' requires an explicit cast
1>..\..\..\..\..\..\..\libraries\sqlite-amalgamation-3080702\sqlite3.c(21411): error C2440: '=' : cannot convert from 'void *' to 'char *'
But there is no error that a header or file is not found. Everything is found and the errors are just outputted above
I have found the solution. I compiled the C code as C++, but changing it was not enough.
I write it for future visitors:
First, I had to change file's (ONLY FILE) property. Right-click on the file and select properties, under the C/C++, select Advanced and then select Compile As and set it to C (neither default nor C++).
Then, you should make sure that your .c file is compiled without clr. Well, to do that, under the same C/C++ set of menu, select "Common Langugae Runtime Support" and set it to No Support....
I'm using Visual Studio 17 and I would add to this, find the settings for "Precompiled Header" and set that to "Not Using Precompiled Headers".
I have this that compiles fine in VC++ 6.0
typedef std::vector<ILBCOM_FieldStruct*> FieldsVector;
FieldsVector m_coll;
FieldsVector::iterator it(&m_coll[Index-1]);
m_coll.erase(it);
I need to compile in Visual Studio C++ 2010
The error message is on the 3rd line:
error C2664: 'std::_Vector_iterator<_Myvec>::_Vector_iterator(const
std::_Vector_iterator<_Myvec> &)' : cannot convert parameter 1 from
'ILBCOM_FieldStruct **' to 'const std::_Vector_iterator<_Myvec> &'
Do you see something wrong?
std::vector<T>::iterator does not have a constructor that converts from T*. It does have a copy constructor:
FieldsVector::iterator it(m_coll.begin()+Index-1);