2017-12-16 10 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; 


} 

같이있는 기능이 필요합니다. &을 사용했지만 컴파일러는 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 
      ^~~~~~~~~~~~ 

감사

입니다
+1

nonconst 참조는 임시에 바인딩 할 수 없습니다. 'const' 참조로 전달하려고 했습니까? 기본적인'std :: vector'는'std :: vector ()'이 될 것입니다. –

+0

@ AlgirdasPreidžius 그래서 const를 사용하면 벡터를 수정하고 오브젝트를 추가 할 수 있습니까? –

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

그러나 처음 세 개의 매개 변수 만 사용하는 함수가 필요한 경우 당신은 단순한 오버로드를 추가로 사용할 수 있습니다 :