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. Android 让输入框输入指定字符的办法

    让输入框输入指定字符的办法 有一个需求 让输入密码的时候只能输入数字字母可见字符 不能输入中文 之前还以为要写代码 还来发现有一个属性可以直接实现 <EditText android:layou ...

  2. CSS3_边框属性之圆角的基本图形案例

    一.正方形 div{ background:#F00; width:100px; height:100px;}   二.长方形 div{background:#F00;width:200px;heig ...

  3. Java Performance - 优化和分析Garbage Collection/垃圾收集

    随着硬件的不断提升,Java Heap 越来越大,合理的垃圾收集调优变得愈发重要.下面介绍一些最佳实践: 注意: 下面不涉及 IBM AIX Java. 同时不介绍原理,仅仅是建议以及初始配置/最佳实 ...

  4. Kafka 快速起步(作者:杜亦舒)

    Kafka 快速起步 原创 2017-01-05 杜亦舒 性能与架构 主要内容:1. kafka 安装.启动2. 消息的 生产.消费3. 配置启动集群4. 集群下的容错测试5. 从文件中导入数据,并导 ...

  5. iOS开发 判断字符串是不是网址

    - (BOOL)isUrlString { NSString *emailRegex = @"[a-zA-z]+://.*"; NSPredicate *emailTest = [ ...

  6. python 键值对的树实现

    #coding:utf-8 __author__ = 'similarface' class KeyedBinaryTree: def __init__(self):self.tree=EmptyNo ...

  7. 显示win7桌面网络.reg

    显示win7桌面网络.reg Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\C ...

  8. 33-Url辅助方法

    Url辅助方法与HTML辅助方法很类似,HTML辅助方法用来产生HTML标签,而Url辅助方法则负责用来产生Url网址. @Url.Action("About") 最后的输出网址如 ...

  9. [转载]Badboy使用教程

    Badboy-系列教程-资料整理: Badboy自动化测试工具1 界面介绍 http://leafwf.blog.51cto.com/872759/1107079 Badboy自动化测试工具2 录制 ...

  10. BluetoothGatt API

    punlic final class BluetoothGatt继承自Object , 实现了BluetoothProfile接口/** 相关的蓝牙协议可http://www.cnki.net/KCM ...