커리어리 트렌드

현직자 Q&A채용공고커리어 에이전트New

#오버로딩

질문 1
해시태그 없이 키워드만 일치하는 질문은 개수에 포함되지 않아요.

일 년 전 · 김영민 님의 질문

템플릿 <<연산자 오버로딩이 궁금합니다.

template<typename E > class Node { public: Node() : next(nullptr), prev(nullptr) {} bool operator<(Node N) { return N.data < data; } bool operator>(Node N) { return N.data > data; } template<typename E> friend ostream& operator<<(ostream& os, const Node<E>& N) { os << N.data; return os; } private: E data; Node<E>* next; Node<E>* prev; friend class LinkedList<E>; }; 다른print 함수{cout<<Node객체.data} 이렇게 E타입의 data를 <<로 출력해야 하는데 [ C2679 이항 '<<': 오른쪽 피연산자로 'const E' 형식을 사용하는 연산자가 없거나 허용되는 변환이 없습니다. ] ​ 자꾸 위와 같은 오류가 뜹니다... 그래서 template<typename E>를 연산자 오버로딩 앞에 붙여봐도 ​ [ C2995 'std::ostream &operator <<(std::ostream &,const Node<E> &)': 함수 템플릿이 이미 정의되었습니다. ] 이런 오류가 발생하구요. 템플릿 타입을 <<로 어떻게 출력하나요??

개발자

#c++

#템플릿

#오버로딩

답변 0

댓글 0

보충이 필요해요 1

조회 64