다음 코드를 컴파일 할 때 이런 에러가 발생했다.
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>
T
와 Container
가 겹친다. 그래서 T
를 TT
로 Containert
를 TContainer
로 변경했다. 에러 없이 컴파일 완료!
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);
...
};