友元黑魔法——在类内定义友元函数

起因是我写了这么一段代码:

template <typename type>
class LIFO_stack : public my_stack<type> {
	template <typename ano_type>
	friend ostream& operator<<(ostream& os, LIFO_stack<ano_type>& s);
}
template <typename type>
ostream& operator<<(ostream& os, LIFO_stack<type>& s) {
	auto it = --s.vec.end();
	for (; it != s.vec.begin(); --it) {
		os << *it << ' ';
	}
	os << *it << endl;
	return os;
}

继续阅读“友元黑魔法——在类内定义友元函数”