2014-07-26 50 views
0
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被定義爲:不能在分配 '庫名稱:: ZlibCompressor' 轉換爲 '庫名稱::壓縮機*'(到數組索引)

Compressor* compressors[256]; 

ZlibCompressor是Compressor的一個子類。

任何想法爲什麼會發生此錯誤?謝謝!

回答

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

類型的options.compressors[0]Compressor *,這是指針。你應該給一個指針。

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