关于C++primer的疑问
来源:互联网 发布:网络十大博客公司 编辑:程序博客网 时间:2024/05/18 13:45
看c++已有半个月了,看到一段代码
checkedptr& checkedptr::operator++(int){checkedptr ret(*this);++*this;return ret;}
就用vs2010实现了一下,代码如下
#include<iostream>using namespace std;class checkedptr{public:checkedptr(int *b,int *e):beg(b),end(e),curr(b){}checkedptr& operator++();checkedptr& operator++(int);friend ostream& operator<<(ostream& out,const checkedptr &c);~checkedptr(){}private:int* beg;int* end;int* curr;};checkedptr& checkedptr::operator++(){if(curr==beg)throw out_of_range("increment past the end of checkedptr");++curr;return *this;}checkedptr& checkedptr::operator++(int){checkedptr ret(*this);++*this;return ret;}ostream& operator<<(ostream& out,const checkedptr &c){out<<*(c.curr);return out;}int main(){int arr[]={1,2,3,4,5,6,7,8,9};checkedptr parr(arr,arr+9);cout<<"++a:"<<++parr;checkedptr par(arr+4,arr+9);cout<<"a++:"<<++par;return 0;}
结果编译没问题,运行时出错。
求大神指导
- 关于C++primer的疑问
- C++Primer练习3.13疑问?
- 《c++primer 》string *pstr = new string; *pstr = str;的疑问
- 关于javascript的疑问
- 关于变压器的疑问
- 关于 LoadLibrary 的疑问
- 关于junit的疑问
- 关于pthread_testcancel()的疑问
- 关于 retainCount 的疑问
- 关于Midi的疑问
- 关于IO的疑问
- 关于const_cast的疑问
- 关于scanf的疑问
- 关于C++的疑问
- 关于sort()的疑问?
- 关于多线程的疑问
- 关于Context的疑问
- 关于typescript的疑问
- Asp.Net请求原理and页面生命周期
- 求a!+b!+c!之和
- .c和.h文件的区别
- 动态LINQ(Lambda表达式)构建
- 7.enum和typedef分析
- 关于C++primer的疑问
- 计算幂函数的几种方法
- 起点事件折射出网络文学产业化困境
- emacs semantic模式简介
- [SQL Server]如何快速查找使用了某个字段的所有存储过程?
- [130324]阿斯那一只
- hdu 2151 简单dp
- 【没有骗你哦】21天精通C++
- 如何用Hadoop计算平均值