2017-12-16 5 views
0

私は機能上からresultsを返すようにしたい、このは、デフォルト値

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; 


} 

のようなものである機能を持つが必要です。私は&を使用しますが、コンパイラは、私は関数定義のstd::vector<PixelData>のデフォルト値を定義する方法、resultsのデフォルト値を必要ですか?

ここ

は私の誤りである

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 
      ^~~~~~~~~~~~ 

おかげ

+1

nonconst参照は一時ファイルにバインドできません。 'const'リファレンスで渡してみましたか?デフォルトの 'std :: vector'を構築しないことに加えて、' std :: vector () 'となるでしょう。 –

+0

@AlgirdasPreidžiusconstを使うとオブジェクトを修正してベクトルに追加できますか? –

+0

@MajidHojati _ "constを使うとオブジェクトを修正してベクターに追加できますか?" 'srsofpoints'の前に' results'パラメータを移動し、デフォルト値の必要性を取り除くのはどうでしょうか? – user0042

答えて

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,*/ 
         ) 
{ 
    // ... 
} 

しかし、最初の3つのパラメータだけを取る関数が必要な場合