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实现系统电话通话过程中自动感应黑屏

    package com.developmenttools.customui.activity; import java.util.HashSet;import java.util.Set; impor ...

  2. 如何将根文件系统制作成yaffs格式,并设置从yaffs启动

    1.利用mkyaffs2image 工具,将根文件系统打包成yaffs镜像包 mkyaffs2image-128M root_qtopia root_qtopia.img 2.设置uboot参数boo ...

  3. Hbase之更新单条数据

    import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.HBaseConfiguration; impo ...

  4. 不能使用tpcc-mysql测试OneProxy

    因为Proxy类的中间件不适合实现prepared statement,所以无法测试,导致我们无法使用标准的测试工具去发布OneProxy的测试结果

  5. 【转】commons-lang.jar包简介

    转自:http://zhidao.baidu.com/share/71b48e6b3e1b1dc73fe705604b9c7584.html 1.下载jar包 包官方下载地址:http://commo ...

  6. HTML5自学笔记[ 8 ]历史管理

    触发历史管理的三种方法: 跳转页面 改变hash值 pushState(在服务器环境下运行) 用hash值来触发历史管理: <!doctype html> <html lang=&q ...

  7. --专访雷果国: 从1.5K到18K 一个程序员的5年成长之路--

    导语:今年三月份,在CSDN博客和新浪微博上有一篇<从1.5K到18K,一个程序员的5年成长之路>被众人分享和传阅,这篇博文首先介绍了作者自学之初薄弱的基础,然后通过流水账形式分享了那个从 ...

  8. Linux下如何查看自己的服务器有没有无线网卡

    还是实验室那台破服务器,连不上网.有没有界面,所以想着如何用一些命令来链接上热点. 当然,在linux下链接wifi没有win下那么一点就好了! 首先我们需要的基本条件就是: 服务器上有无线网卡.[r ...

  9. HDU-----(1083)Courses(最大匹配)

    Courses Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total S ...

  10. 手动实现KVO

    前言 KVO(Key-Value Observing, 键值观察), KVO的实现也依赖于runtime. 当你对一个对象进行观察时, 系统会动态创建一个类继承自原类, 然后重写被观察属性的sette ...