2013-06-13 15 views
1

我想知道你能不能幫我一個小問題空字節我有:c + +創建

我目前發民在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; 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); 
+1

你可以通過'0',或者'nullptr'因爲參數類型是'字節*'。或者嘗試'reinterpret_cast (CryptoPP :: SHA1 :: StaticAlgorithmName())' – perreal

+0

你的問題是什麼? – Aravind

回答

2

正如評論說,這裏的問題是與函數的第一個參數,而不是與你們以前unused第三。因爲我想你需要這個參數,你應該嘗試的建議:

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);