我有一个像这样的功能
static int locationinfo( const char *pszSrcFilename
, const char *pszLocX
, const char *pszLocY
, const char *Srsofpoints=NULL
, std::vector<PixelData>& results=std::vector<PixelData>
/* char **papszOpenOptions = NULL,int nOverview = -1,*/
)
{
--filling results
return 1;
}
我想从上面的函数返回results
。我使用&
但编译器需要results
的默认值,如何在函数定义中为std::vector<PixelData>
定义默认值?
这是我的错误
error: default argument missing for parameter 5 of ‘int locationinfo(const char*, const char*, const char*, const char*, std::vector<PixelData>&)’
static int locationinfo(const char *pszSrcFilename , const char *pszLocX ,const char *pszLocY,const char *Srsofpoints=NULL
^~~~~~~~~~~~
感谢
答案 0 :(得分:2)
您可以简单地重新排序参数,以消除对const
引用和默认参数声明的需求:
static int locationinfo( const char *pszSrcFilename
, const char *pszLocX
, const char *pszLocY
, std::vector<PixelData>& results // <<<<
, const char *Srsofpoints=NULL // <<<<
/* char **papszOpenOptions = NULL,int nOverview = -1,*/
)
{
// ...
}
如果你需要一个仅采用前三个参数的函数,你还可以使用一个简单的过载:
static int locationinfo( const char *pszSrcFilename
, const char *pszLocX
, const char *pszLocY
) {
std::vector<PixelData> dummy;
return locationinfo(pszSrcFilename,pszLocX,pszLocY,dummy);
}