본문 바로가기
컴퓨터/디버깅

declaration of OOO shadows a parameter

by adnoctum 2010. 5. 18.
다음과 같은 에러가 났다.

환경: GCC 4.1.2 20080704 (Red Hat 4.1.2-46) on CentOS 5.4

/LJSLibrary/source/statutil.cpp:386: error: declaration of ‘int rank’ shadows a parameter

   에러 메세지는 'int rank'라 선언하는 것이 파라미터를 가린다는 얘기로, 중복선언되어 있음을 짐작할 수 있다. 실제로 에러가 난 부분을 보면 다음과 같다.

  373 bool get_rank_list_from_value_list(const std::vector<double>& value, std::vector<int>* rank)

  374 {

  375         std::vector<std::pair<double,int> > value_index;

  376         std::vector<double>::const_iterator pos = value.begin();

  377         int idx = 0;

  378         for(; pos != value.end(); pos++,idx++){

  379                 value_index.push_back(std::make_pair<double,int>(*pos,idx));

  380         }

  381 

  382         std::sort(value_index.begin(), value_index.end(), compare_by_first);

  383 

  384         std::map<int,int> index2rank;

  385         std::vector<std::pair<double,int> >::const_iterator rpos = value_index.begin();

  386         int rank = 0;  // 에러가 난 부분

  387         for(; rpos != value_index.end(); rpos++,rank++){

  388                 index2rank.insert(std::make_pair<int,int>(rpos->second, rank));

  389         }

  390 

  391         int i = 0; int n = (int)(value.size());

  392         for(i = 0; i<n; i++){

  393                 rank->push_back(index2rank[i]);

  394         }

  395 

  396         return true;

  397 }


373번째 줄의 rank 와 386번째 줄의 rank 가 동일한 이름의 다른 type 으로 선언되어 있는 것을 볼 수 있다. 따라서 변수의 이름을 다르게 해주면 되겠다. 개인적인 코딩 규칙에 따라 parameter의 [rank] 를 [_rank]로 변경해 주었다.

Visual C++ 의 경우 주로 이런 경우 variable re-declaration 이 났던 것 같은데... 여하튼 GCC의 에러 메세지는 역시나 명확하다.