虽然无论是以前还是现在,我都无法成为日坂菜乃。
月度归档: 2018 年 7 月
友元黑魔法——在类内定义友元函数
起因是我写了这么一段代码:
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;
}
(续上篇)被自己蠢到的关于const关键字的坑
在我实现的LIFO_stack类里面,有一个print()函数,而这个函数是通过调用<<操作符实现的:
继承模板类的子类无法访问protected成员(坑
最近花了点时间把essential C++的第五章(讲继承)和第六章(讲模板)的部分给看完了。自己试着写一个栈来练习一下,以下是代码
