当我尝试编译这个(g++)时:
template<typename T>
struct A {
struct B { };
template<typename S>
friend A<S>& operator +(A<S> const &, A<S> const &);
};
template<typename T>
A<T>& operator +(A<T> const &a, A<T> const &b) {
A<T>::B *x;
return a;
}
main() { }
我明白了
test.cpp: In function "A<T>& operator+(const A<T>&, const A<T>&)":
test.cpp:12:11: error: "x" was not declared in this scope
为什么?
[忽略:如果我不包括这一行,堆栈溢出说我保存时我的帖子中有太多代码]