cannot convert parameter 1 from 'CStringListX *__w64 ' to 'CStringListX &' - c++

I am making a wrapper for a Cpp DLL, but am getting trouble with the following function:
void PyGetUSBDeviceNames(DFUEngine *DFUe, CStringListX &devices)
{
return DFUe->GetUSBDeviceNames(&devices);
}
I get the error:
error C2664: 'DFUEngine::GetUSBDeviceNames' : cannot convert parameter 1 from 'CStringListX *__w64 ' to 'CStringListX &'
The function GetUSBDeviceNames is defined in the h file as:
static int GetUSBDeviceNames(CStringListX &devices);
how can I get around this one?
Thanks alot

Remove the unneeded &:
return DFUe->GetUSBDeviceNames(devices);

Related

Convert from 'QChar' to 'wchar_t'

I need to pass a QChar to a function that expects a wchar_t:
void myFunc(wchar_t wch);
Trying to just pass the QChar fails with an error:
error: C2664: 'myFunc' : cannot convert parameter 1 from 'QChar' to 'wchar_t'
Found the answer even while I was asking the question, I needed to use QChar::unicode().
wchar_t wch = qch.unicode();

error C2440 and functors

maybe you would know, I get an error:
error C2440: 'initializing' : cannot convert from 'int'
Conversion from integral type to pointer type requires reinterpret_cast
It goes to ' file in MS VS 2010 folder:
template<class _Other1,
class _Other2>
_Pair_base(_Other1&& _Val1, _Other2&& _Val2)
: first(_STD forward<_Other1>(_Val1)),
second(_STD forward<_Other2>(_Val2))
{ // construct from moved values
}
I was looking for different solutions but could not find a correct one.
The error says
'initializing' : cannot convert from 'int' to 'EnterFunctor *'
The only part of your code you share is
functors.push_back(make_pair(sessionStartFunc,
pair<EnterFunctor*, ExitFunctor*>(NULL,sessionStartExit)));
If NULL is #defined as 0 this gives you an int but you promised a pair of pointers, so as the next line of the error says you can use a cast to make NULL the right type of pointer.

C++ list remove_if compile error

The error message I'm getting for the code below is:
error C2662: 'DamageNumbers::IsAlive' : cannot convert 'this' pointer from 'const DamageNumbers' to 'DamageNumbers &'
1> Conversion loses qualifiers
.
bool CheckDamageNumbersAlive(const DamageNumbers& e)
{
return !e.IsAlive();
}
I want to remove objects from a list when IsAlive() returns false for the objects in that list.
Your method
bool DamageNumbers::IsAlive() {...}
should be const:
bool DamageNumbers::IsAlive() const {...}

C++ Cannot convert from deferred::SafePtr<T> to T*

I have made a test case to show the problems I am running into. Please forgive me my ignorance on the issues of Deferred libraries and pointer casting. The only library included in the deferred.lib.
#include <deferred/deferred.h>
using namespace deferred;
SafePtr<Deferred> recordTime(int time)
{
SafePtr<Deferred> d = createDeferred();
SafePtr<CallbackData> p = new PointerCBD< char>( 0 );
d->execute(p);
return d;
}
int main(int argc, char* argv[])
{
while(1)
{
SafePtr<Deferred> d = recordTime(1000);
d->waitHereForCompletion();
char* c = dynamic_pointer_cast<char>(d->endResult());
}
return 0;
}
When I try and compile in Windows XP with VS2008 I get:
Error C2440: 'initializing' : cannot convert from
'deferred:SafePtr' to 'char *' with
[T=char]
No user-defined-conversion operator available that can perform this
conversion, or the operator cannot be called.
I have tried this command to return a pointer, rather than a SafePtr:
ManagerTimings* t = dynamic_pointer_cast<ManagerTimings>(d->endResult()).get();
Then I get this error:
Error C2664: 'deferred::intrusive_ptr_release' : cannot convert
parameter 1 from 'char *' to
'deferred:ReferenceCountable *'
I have tried this command:
ManagerTimings* t = dynamic_pointer_cast<ManagerTimings>(d->endResult().get());
Then I get this error:
Error C2784: 'deferred::SafePtr deferred::dynamic_pointer_cast(const deferred::SafePtr< U > &)' : could not deduce template argument for 'const deferred::SafePtr< U > &' from 'deferred::CallbackData *'
Try this:
ManagerTimings* t = dynamic_pointer_cast<ManagerTimings>(d->endResult().get());
if you want to get an "unsafe" pointer, or probably this:
SafePtr<ManagerTimings> t= dynamic_pointer_cast<ManagerTimings>(d->endResult());
to get a safe ManagerTimings pointer. I don't know what library you are using, but I suspect that dynamic_pointer_cast can convert a SafePtr to another SafePtr. Or it just converts pointers.
&*d->endResult()
I think from this code endResult is the SafePtr you're having trouble with.

Parsing LPTSTR* command line args with boost::program_options

I am having a problem with command line parsing with boost:program_options. The quickest way to explain it is to show the code so:
const std::vector<tstring> args;
if (ac > 0 && NULL!=av) //ac is a ULONG
{
for (int i = 0; i < ac; i++)
{
args.push_back(av[i]); //av is an LPTSTR pointer (pointer to TCHAR*)
}
}
po::command_line_parser parser(args);
The parser ctor is supposed to take a const std::vector<charT>
typedef basic_command_line_parser<char> command_line_parser;
typedef basic_command_line_parser<wchar_t> wcommand_line_parser;
/** Creates instance of 'command_line_parser', passes parameters to it,
and returns the result of calling the 'run' method.
*/
template<class charT>
class basic_command_line_parser : private detail::cmdline {
public:
/** Creates a command line parser for the specified arguments
list. The 'args' parameter should not include program name.
*/
basic_command_line_parser(const std::vector<
std::basic_string<charT> >& args);
tstring in my program is
typedef std::basic_string<TCHAR> tstring;
The error I get is:
Error 16 error C2664: 'boost::program_options::basic_command_line_parser<charT>::basic_command_line_parser(const std::vector<_Ty> &)' : cannot convert parameter 1 from 'const std::vector<_Ty>' to 'const std::vector<_Ty> &' myfile.cpp 329
Where, oh where, am I going astray? I've tried all kinds of casting and re-defining, but nothing has worked and I'm at the end of my tether.
Edit #Zac:
Making the changes you suggested... I get the error:
Error 14 error C2664: boost::program_options::basic_command_line_parser<charT>::basic_command_line_parser(const std::vector<_Ty> &)' : cannot convert parameter 1 from 'std::vector<_Ty>' to 'const std::vector<_Ty> &' MyFile.cpp 328
Edit
Just to point out that I am using Visual Studio 2008 VC9 compiler
You seem to be using a unicode build, so either explicitly use the wide char version:
po::wcommand_line_parser parser(args);
or the more flexible:
po::basic_command_line_parser<TCHAR> parser(args);
The line you went astray with is below:
const std::vector<tstring> args;
Change it to:
std::vector<tstring> args;