C++ C++;创建空字节
我想知道你是否能帮我解决我的一个小问题: 我目前正在使用C++/Qt进行开发,并收到以下错误消息:C++ C++;创建空字节,c++,qt,C++,Qt,我想知道你是否能帮我解决我的一个小问题: 我目前正在使用C++/Qt进行开发,并收到以下错误消息: P:\Produkt\Savor_V100\webapi.cpp:84: error: C2664: 'CryptoPP::PasswordBasedKeyDerivationFunction::DeriveKey' : cannot convert parameter 1 from 'const char *' to 'byte *' Types pointed to are unrelated
P:\Produkt\Savor_V100\webapi.cpp:84: error: C2664: 'CryptoPP::PasswordBasedKeyDerivationFunction::DeriveKey' : cannot convert parameter 1 from 'const char *' to 'byte *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
函数中的参数未使用,因此我想在其中传递一个空字节。经过一点研究,我发现一个字节只是一个简单的无符号字符
我的代码如下所示:
byte* unused;
qDebug() << CryptoPP::PasswordBasedKeyDerivationFunction::DeriveKey(CryptoPP::SHA1::StaticAlgorithmName(), CryptoPP::SHA1::BLOCKSIZE, unused, user->getPassword(), sizeof(user->getPassword()), user->getSerial(), sizeof(user->getSerial()), 0 );
byte*未使用;
qDebug()getPassword(),sizeof(用户->getPassword()),用户->getSerial(),sizeof(用户->getSerial()),0);
如评论中所述,这里的问题是函数的第一个参数,而不是使用未使用的的第三个参数。因为我想您确实需要这个参数,所以您应该按照建议尝试:
qDebug() << CryptoPP::PasswordBasedKeyDerivationFunction::DeriveKey(
reinterpret_cast<byte*>(CryptoPP::SHA1::StaticAlgorithmName()),
CryptoPP::SHA1::BLOCKSIZE,
0,
user->getPassword(),
sizeof(user->getPassword()),
user->getSerial(),
sizeof(user->getSerial()),
0 );
qDebug()获取密码(),
sizeof(用户->获取密码()),
用户->getSerial(),
sizeof(用户->getSerial()),
0 );
您可以传递0
,或者nullptr
,因为参数类型是byte*
。或者尝试重新解释(CryptoPP::SHA1::StaticAlgorithmName())
您的问题是什么?