gpt4 book ai didi

c++ - 无法在赋值中将 ‘libraryname::ZlibCompressor’ 转换为 ‘libraryname::Compressor*’(到数组索引)

转载 作者:行者123 更新时间:2023-11-28 06:46:03 25 4
gpt4 key购买 nike

main.cc: In function ‘int main()’:
main.cc:10:26: error: cannot convert ‘libraryname::ZlibCompressor’ to ‘libraryname::Compressor*’ in assignment
options.compressors[0] = libraryname::ZlibCompressor();

options 是一个结构体,compressors 定义为:

Compressor* compressors[256];

ZlibCompressor 是 Compressor 的子类。

知道为什么会出现这个错误吗?谢谢!

最佳答案

options.compressors[0] = libraryname::ZlibCompressor();

options.compressors[0] 的类型是Compressor *,也就是指针。你应该给个指点。

libraryname::ZlibCompressor zc;
options.compressors[0] = &zc;

关于c++ - 无法在赋值中将 ‘libraryname::ZlibCompressor’ 转换为 ‘libraryname::Compressor*’(到数组索引),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24968931/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com