shadows template parameter 오류?

😎·2023년 1월 31일
0

다음 코드를 컴파일 할 때 이런 에러가 발생했다.

template <typename T, typename Container = ft::vector<T> >
class stack {
 public:
  ...

 protected:
  ...

 public:
  explicit stack(const container_type &ctnr = container_type()) : c(ctnr) {}

  ~stack() {}

  ...

  template <typename T, typename Container>
  friend bool operator==(const stack<T, Container> &lhs,
                         const stack<T, Container> &rhs);

  template <typename T, typename Container>
  friend bool operator!=(const stack<T, Container> &lhs,
                         const stack<T, Container> &rhs);

  template <typename T, typename Container>
  friend bool operator<(const stack<T, Container> &lhs,
                        const stack<T, Container> &rhs);
...
};

코드 구조를 보면 template 안에 template 을 선언했는데, 같은 이름의 매개 변수를 사용했기 때문이다.


  • 맨 위 줄
    template <typename T, typename Container = ft::vector<T> > class stack {
  • 아래 부분
    template <typename T, typename Container>

TContainer 가 겹친다. 그래서 TTTContainertTContainer 로 변경했다. 에러 없이 컴파일 완료!

template <typename T, typename Container = ft::vector<T> >
class stack {
 public:
  ...

 protected:
  ...

 public:
  explicit stack(const container_type &ctnr = container_type()) : c(ctnr) {}

  ~stack() {}

  ...

  template <typename TT, typename TContainer>
  friend bool operator==(const stack<TT, TContainer> &lhs,
                         const stack<TT, TContainer> &rhs);

  template <typename TT, typename Container>
  friend bool operator!=(const stack<TT, TContainer> &lhs,
                         const stack<TT, TContainer> &rhs);

  template <typename TT, typename Container>
  friend bool operator<(const stack<TT, TContainer> &lhs,
                        const stack<TT, TContainer> &rhs);
...
};
profile
jaekim

0개의 댓글

관련 채용 정보