SGI STL은 나 자신만큼 오래되었다는 것을 알고 있습니다. 그러나 나는 아직도 그것을 알아 내고 싶습니다.SGI STL의 바운드 친구 템플릿
template <class T, class Sequence = Deque<T> >
class Stack {
friend bool operator== __STL_NULL_TMPL_ARGS (const Stack&, const Stack&);
friend bool operator< __STL_NULL_TMPL_ARGS (const Stack&, const Stack&);
protected:
Sequence c;
};
template <class T, class Sequence>
bool operator== (const Stack<T, Sequence>& x, const Stack<T, Sequence>& y){
return x.c == y.c;
}
template <class T, class Sequence>
bool operator< (const Stack<T, Sequence>& x, const Stack<T, Sequence>& y){
return x.c < y.c;
}
stl_config.h에서 __STL_NULL_TMPL_ARGS
는 다음과 같이 정의된다 : stl_stack.h에서
는이 같은 일부 코드가
# ifdef __STL_CLASS_PARTIAL_SPECIALIZATION
# define __STL_TEMPLATE_NULL template<>
# else
# define __STL_TEMPLATE_NULL
# endif
을하지만 G ++ 4.9.2로 컴파일하려고 할 때, 컴파일러는 다음과 같이 말했다 :
In file included from stack.cpp:1:0:
stack.h:13:22: error: declaration of ‘operator==’ as non-function
friend bool operator== __STL_NULL_TMPL_ARGS (const Stack&, const Stack&);
^
stack.h:13:22: error: expected ‘;’ at end of member declaration
In file included from iterator.h:3:0,
from deque.h:6,
from stack.h:5,
from stack.cpp:1:
stl_config.h:111:31: error: expected unqualified-id before ‘<’ token
# define __STL_NULL_TMPL_ARGS <>
^
stack.h:13:25: note: in expansion of macro ‘__STL_NULL_TMPL_ARGS’
friend bool operator== __STL_NULL_TMPL_ARGS (const Stack&, const Stack&);
내가 왜 그런지 모르겠다. 내 컴퓨터에서 같은 코드를 컴파일 할 수 없으면이 코드가 현재 불법 코드인가?
대단히 감사합니다!
당신은'찾고 될 수 있습니다 그리고 선언은
stack
의 전방 선언이 필요합니다 # define __STL_NULL_TMPL_ARGS <>', line 192. – Potatoswatter코드가 더 이상 적합하지 않을 수 있지만 질문이 더 많은 템플릿을위한 구문과 관련이 있다면 여기를 살펴보십시오. http://stackoverflow.com/a/35891188/3747990 – Niall
''# define __STL_NULL_TMPL_ARGS <>'''이 포함되어 있습니다. @Potatoswatter – Jiahao