C++ "从'无效*'到'crypto_aes_ctx*的无效转换"
C++ 'invalid conversion from ‘void*’ to ‘crypto_aes_ctx*’
为了了解矢量和并行化,我目前正在尝试用VC并行化我的程序(http://code.compeng.uni-frankfurt.de/projects/vc)。我的程序是用C编写的,但VC要求使用C++。因此,我将文件重命名为.cpp,并尝试编译它们。我得到三个编译错误,它们都是相同的
error: invalid conversion from ‘void*’ to ‘crypto_aes_ctx*’
代码是以下
int crypto_aes_set_key(struct crypto_tfm *tfm, const uint8_t *in_key,
unsigned int key_len)
{
struct crypto_aes_ctx *ctx = crypto_tfm_ctx(tfm);
uint32_t *flags = &tfm->crt_flags;
int ret;
ret = crypto_aes_expand_key(ctx, in_key, key_len);
if (!ret)
return 0;
*flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
return -EINVAL;
}
如何修复此问题以使我的代码与c++编译器一起工作?
C++中的键入比C更严格,因此必须使用强制转换来告诉编译器void
指针实际是什么。
struct crypto_aes_ctx *ctx = (struct crypto_aes_ctx*) crypto_tfm_ctx(tfm);
请注意,我使用的是C样式转换,以防您想继续使用C中的代码。对于C++,您将使用reinterpret_cast
。
在C++中,如果没有显式的重新解释强制转换,则不能将类型为void *
的指针分配给任何其他类型的指针。
如果语句中出现错误
struct crypto_aes_ctx *ctx = crypto_tfm_ctx(tfm);
然后你必须写
struct crypto_aes_ctx *ctx = reinterpret_cast<struct crypto_aes_ctx *>( crypto_tfm_ctx(tfm) );
相关文章:
- Openssl 1.1.1d无效使用不完整的类型"struct dsa_st"
- 无法访问嵌套类.类的使用无效
- 如果用户输入无效,如何使用字符串变量-C++重复输入命令
- 如何解决错误:SCIP C++中的 SCIP 阶段无效 <10>
- 在没有参数列表的情况下使用模板名称"Event"无效,模板问题
- FFMPEG配置文件级别id大小无效
- 错误:从"int"到枚举c++的转换无效
- 如何修复此错误:className::className的无效使用
- 为什么将值返回函数传递给重载=运算符对运算符函数有效,而对其他运算符无效
- C++-模板嵌套类的引用初始化无效
- 错误:无效的预处理指令 #i 的意思是 #if?
- 多维数组 C++ 中数组下标的类型"int[int]"无效
- 在 C++ 中使用正则表达式错误时出现问题 括号表达式中的范围无效
- 从 'int' 到 'int*' CPP 的转换无效
- 如何接受 [ENTER] 键作为无效输入并发送错误消息
- 由于无效的 ValidateRgn() 子窗口不会收到WM_PAINT消息
- C++ PTHREADS - 无效转换无效*(*)()到无效*(*)(无效*)
- 声明为无效的变量或字段'...' Ardunio 编译器上的错误
- 数组下标的类型"float*[float]"无效
- 修改 std::vector 会使迭代器无效吗?