return 来自函数的 std::Vector<object> 需要默认值
return a std::Vector<object> from function needs a default value
我有一个函数是这样的
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;
}
我想 return 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
^~~~~~~~~~~~
谢谢
您可以简单地重新排序您的参数以摆脱对 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);
}
我有一个函数是这样的
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;
}
我想 return 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
^~~~~~~~~~~~
谢谢
您可以简单地重新排序您的参数以摆脱对 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);
}