1

I have this code using lodepng library for loading PNG files. Library is OK, succesfully used in other projects, wihout problem.

const std::string tmpString = mapFileName.GetConstString();
    std::vector<unsigned char> xx;
    unsigned int error = lodepng::decode(xx, (unsigned int)this->mapWidth, (unsigned int)this->mapHeight, tmpString, LCT_GREY, (unsigned int)8);        

I want to compile this, but getting weird error message.

MapHelper.cpp(72): error C2665: 'lodepng::decode' : none of the 5 overloads could convert all the argument types
          c:\ImageUtils\lodepng.h(200): could be 'unsigned int lodepng::decode(std::vector<_Ty> &,unsigned int &,unsigned int &,const unsigned char *,size_t,LodePNGColorType,unsigned int)'
         with
          [
              _Ty=uint8
          ]
          c:\ImageUtils\lodepng.h(203): or       'unsigned int lodepng::decode(std::vector<_Ty> &,unsigned int &,unsigned int &,const std::vector<_Ty> &,LodePNGColorType,unsigned int)'
          with
          [
              _Ty=uint8
          ]
          c:\ImageUtils\lodepng.h(211): or       'unsigned int lodepng::decode(std::vector<_Ty> &,unsigned int &,unsigned int &,const std::string &,LodePNGColorType,unsigned int)'
          with         
 [
             _Ty=uint8
          ]
          c:\ImageUtils\lodepng.h(759): or       'unsigned int lodepng::decode(std::vector<_Ty> &,unsigned int &,unsigned int &,lodepng::State &,const unsigned char *,size_t)'
          with
          [
              _Ty=uint8
          ]
          while trying to match the argument list '(std::vector<_Ty>, unsigned int, unsigned int, const std::string, LodePNGColorType, unsigned int)'
          with
          [
              _Ty=uint8
          ]

I cant see whats wrong, types of input parametrs are same as in library and there can be no collision in types.

EDIT Function, where I have lodepng::decode is not const

4

1 回答 1

4

好吧,我本来希望得到更精确的错误消息,但是鉴于此签名存在过载

'(std::vector<_Ty> &,unsigned int &,unsigned int &,const std::string &, LodePNGColorType, unsigned int)'

与您自己的调用相比

'(std::vector<_Ty>, unsigned int, unsigned int, const std::string, LodePNGColorType, unsigned int)'

unsigned int&那么问题一定出在你供给的同时前者想要的事实unsigned int。虽然这通常很好,但在这种情况下并非如此,因为您unsigned int在函数调用中强制转换为,创建了一个 R 值。所以试试这个:

unsigned int wd = (unsigned int)this->mapWidth,
             ht = (unsigned int)this->mapHeight;
unsigned int error = lodepng::decode(xx, wd, ht, tmpString, LCT_GREY, (unsigned int)8); 

通过引用传递通常用于将输出返回给调用代码。如果wd,ht仅用作输出,那么实际上您不需要初始化它们并且

unsigned int wd, ht;

已经足够好了。无论哪种方式wdht函数返回后都会有新值,您可能需要完成

this->mapWidth = wd;
this->mapHeight = ht;
于 2013-05-25T16:03:41.050 回答