How to fix this error: Error C2664 'void…
- User
How to fix this error: Error C2664 'void RGN::Modules::Wallets::WalletsModule::CreateWalletAsync(std::string &,const std::function<void (RGN::Modules::Wallets::CreateWalletResponseData &)> &,const std::function<void (int,std::string)> &)': cannot convert argument 1 from 'std::string' to 'std::string &'
void UBP_WalletsModule::CreateWallet(const FString& password, FCreateWalletSuccessResponse successEvent, FWalletsFailResponse failEvent) { WalletsModule::CreateWalletAsync(std::string(TCHAR_TO_UTF8(*password)), [successEvent](CreateWalletResponseData response) { json responseJson = response; FString responseJsonString = FString(responseJson.dump().c_str()); FBP_CreateWalletResponseData bpResponse; FJsonObjectConverter::JsonObjectStringToUStruct<FBP_CreateWalletResponseData>(responseJsonString, &bpResponse, 0, 0); successEvent.ExecuteIfBound(bpResponse); }, [failEvent](int code, std::string message) { failEvent.ExecuteIfBound(static_cast(code), FString(message.c_str())); } ); }
- Assistant
The error message indicates that there is a problem with argument 1 in the function call
WalletsModule::CreateWalletAsync(). The argument should be a reference to astd::string, but you are passing astd::stringvalue.To fix this error, you need to change the argument type in the lambda function to accept a reference to
std::stringinstead ofstd::string. Here's the updated code:void UBP_WalletsModule::CreateWallet(const FString& password, FCreateWalletSuccessResponse successEvent, FWalletsFailResponse failEvent) { std::string passwordStr(TCHAR_TO_UTF8(*password)); WalletsModule::CreateWalletAsync(passwordStr, [successEvent](CreateWalletResponseData response) { json responseJson = response; FString responseJsonString = FString(responseJson.dump().c_str()); FBP_CreateWalletResponseData bpResponse; FJsonObjectConverter::JsonObjectStringToUStruct<FBP_CreateWalletResponseData>(responseJsonString, &bpResponse, 0, 0); successEvent.ExecuteIfBound(bpResponse); }, [failEvent](int code, const std::string& message) { failEvent.ExecuteIfBound(static_cast<int32>(code), FString(message.c_str())); } ); }In this updated code, the
passwordFString is converted to astd::stringnamedpasswordStrbefore passing it toCreateWalletAsync(). The lambda function for the failure case is also updated to accept a reference tostd::stringfor themessageparameter.