1,c++规定后缀形式的++操作符有一个int行的参数,被调用时,编译器自动加一个0作为参数给他

2,前缀返回一个reference,后缀返回一个const对象

///////////////////////////////////////////////////////////////////////////////
//
// FileName : meffect_item5.h
// Version : 0.10
// Author : Ryan Han
// Date : 2013/11/18
// Comment : prefix and postfix
//
///////////////////////////////////////////////////////////////////////////////
#ifndef MEFFECT_ITEM5_H
#define MEFFECT_ITEM5_H
#include <iostream>
using namespace std; class A{
friend ostream& operator <<(ostream &os, const A &a);
public:
A(int initvalue=, int initstep=):value(initvalue), step(initstep){} //prefix
A& operator++(){
cout << "A& operator++() was called" << endl;
value+=step;
return *this;
} //postfix
const A operator++(int){
cout << "const A operator++(int) was called." << endl;
const A oldA = *this;
++(*this);
return oldA;
}
private:
int value;
int step;
}; #endif
///////////////////////////////////////////////////////////////////////////////
//
// FileName : meffect_item5.cpp
// Version : 0.10
// Author : Ryan Han
// Date : 2013/11/18
// Comment : prefix and postfix
//
///////////////////////////////////////////////////////////////////////////////
#include <iostream>
#include "meffect_item5.h"
using namespace std; ostream& operator<<(ostream &os, const A&a)
{
return os<<a.value;
}
int main(){
int i = ; //postfix return a const value
//i++++; //prefix return a reference
++++i; A a(,);
cout << a++ << endl;
cout << ++a << endl;
A b(,);
cout << b.operator++() << endl;
cout << b.operator++() << endl; return ;
}

C++-前缀和后缀的更多相关文章

  1. 递归算法(二)——前缀转后缀

    源码:pretopost.cpp #include "stdafx.h" #include <stdio.h> #include <stack> /**** ...

  2. POJ 2752 Seek the Name, Seek the Fame (KMP的next函数,求前缀和后缀的匹配长度)

    给一个字符串S,求出所有前缀,使得这个前缀也正好是S的后缀.升序输出所有情况前缀的长度.KMP中的next[i]的意义就是:前面长度为i的子串的前缀和后缀的最大匹配长度.明白了next[i],那么这道 ...

  3. 【Todo】字符串相关的各种算法,以及用到的各种数据结构,包括前缀树后缀树等各种树

    另开一文分析字符串相关的各种算法,以及用到的各种数据结构,包括前缀树后缀树等各种树. 先来一个汇总, 算法: 本文中提到的字符串匹配算法有:KMP, BM, Horspool, Sunday, BF, ...

  4. 关于字符串 “*****AB**C*D*****” 中前缀、后缀和中间 '*' 的处理

    一.删除前缀 '*' #include<iostream> #include<cstdio> using namespace std; //主函数 int main() { ] ...

  5. POJ 2752 Seek the Name, Seek the Fame(求所有既是前缀又是后缀的子串长度)

    题目链接:http://poj.org/problem?id=2752 题意:给你一个字符串,求出所有前缀后缀(既是前缀又是后缀的子串)的长度 思路:首先整个字符串肯定既是前缀又是后缀,为最大的前缀后 ...

  6. 【分治-前缀积后缀积】JS Window @2018acm徐州邀请赛G

    问题 G: JS Window 时间限制: 2 Sec  内存限制: 512 MB 题目描述 JSZKC has an array A of N integers. More over, he has ...

  7. POJ 2752 Seek the Name,Seek the Fame(KMP,前缀与后缀相等)

    Seek the Name,Seek the Fame 过了个年,缓了这么多天终于开始刷题了,好颓废~(-.-)~ 我发现在家真的很难去学习,因为你还要陪父母,干活,做家务等等 但是还是不能浪费时间啊 ...

  8. HDU6025 Coprime Sequence —— 前缀和 & 后缀和

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6025 Coprime Sequence Time Limit: 2000/1000 MS (Java/ ...

  9. bootstrap历练实例:复选框或单选按钮作为输入框组的前缀或后缀

    <!DOCTYPE html><html><head><meta http-equiv="Content-Type" content=&q ...

  10. bootstrap历练实例:按钮作为输入框组前缀或后缀

    <!DOCTYPE html><html><head><meta http-equiv="Content-Type" content=&q ...

随机推荐

  1. CTEX里的函数、符号及特殊字符

    CTEX里的函数.符号及特殊字符 声调 语法 效果 语法 效果 语法 效果 \bar{a}   \acute{a}   \check{a}   \grave{a}   \tilde{a}   \hat ...

  2. windows多线程框架

    #include <iostream> #include <windows.h> using namespace std; HANDLE hMutex; //public : ...

  3. SpringMVC简单构造restful, 并返回json

    https://my.oschina.net/u/2272916/blog/352297

  4. 探究requestDisallowInterceptTouchEvent失效的原因

    昨天在用requestDisallowInterceptTouchEvent的时候,发如今设置了requestDisallowInterceptTouchEvent(true)之后,父View的onI ...

  5. rsa加密--选择padding模式需要注意的问题。。。

    最近在做一个项目中需要,在android对一个密码字段首先进行 一次md5加密后再进行一次rsa加密,然后把加密的结果通过 json协议传输给nginx服务器进行解密.在android中,可以直接 使 ...

  6. vb 和vb.net的区别

    vb 和vb.net的区别 源地址:http://blog.csdn.net/xjc1278003262/article/details/8805324 在随着VB.NET的 发展,大部分人都放弃使用 ...

  7. 错误 undefined reference to __cxa_guard_acquire/release

    用gcc编译 c++ 程序时,出现错误 undefined reference to __cxa_guard_acquire linker error, 但是用icc可以正常编译, 问题出在stati ...

  8. Linux Bash代码 利用for循环实现命令的多次执行

    Linux Bash代码 [yuanhao15@lu01 libsvm-rank-2.81]$ for ((i=0; i<=19; i++)) do ./svm-train -s 5 -c 10 ...

  9.  BP神经网络

     BP神经网络基本原理 BP神经网络是一种单向传播的多层前向网络,具有三层或多层以上的神经网络结构,其中包含输入层.隐含层和输出层的三层网络应用最为普遍. 网络中的上下层之间实现全连接,而每层神经元之 ...

  10. 在Handler.ashx文件中使用session

    使用jquery调用handler文件中的方法,需要使用session,默认生成的文件中,不可以直接使用session.按照以下步骤,即可以通过session与其他的aspx页面的session进行数 ...