C++-前缀和后缀
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++-前缀和后缀的更多相关文章
- 递归算法(二)——前缀转后缀
源码:pretopost.cpp #include "stdafx.h" #include <stdio.h> #include <stack> /**** ...
- POJ 2752 Seek the Name, Seek the Fame (KMP的next函数,求前缀和后缀的匹配长度)
给一个字符串S,求出所有前缀,使得这个前缀也正好是S的后缀.升序输出所有情况前缀的长度.KMP中的next[i]的意义就是:前面长度为i的子串的前缀和后缀的最大匹配长度.明白了next[i],那么这道 ...
- 【Todo】字符串相关的各种算法,以及用到的各种数据结构,包括前缀树后缀树等各种树
另开一文分析字符串相关的各种算法,以及用到的各种数据结构,包括前缀树后缀树等各种树. 先来一个汇总, 算法: 本文中提到的字符串匹配算法有:KMP, BM, Horspool, Sunday, BF, ...
- 关于字符串 “*****AB**C*D*****” 中前缀、后缀和中间 '*' 的处理
一.删除前缀 '*' #include<iostream> #include<cstdio> using namespace std; //主函数 int main() { ] ...
- POJ 2752 Seek the Name, Seek the Fame(求所有既是前缀又是后缀的子串长度)
题目链接:http://poj.org/problem?id=2752 题意:给你一个字符串,求出所有前缀后缀(既是前缀又是后缀的子串)的长度 思路:首先整个字符串肯定既是前缀又是后缀,为最大的前缀后 ...
- 【分治-前缀积后缀积】JS Window @2018acm徐州邀请赛G
问题 G: JS Window 时间限制: 2 Sec 内存限制: 512 MB 题目描述 JSZKC has an array A of N integers. More over, he has ...
- POJ 2752 Seek the Name,Seek the Fame(KMP,前缀与后缀相等)
Seek the Name,Seek the Fame 过了个年,缓了这么多天终于开始刷题了,好颓废~(-.-)~ 我发现在家真的很难去学习,因为你还要陪父母,干活,做家务等等 但是还是不能浪费时间啊 ...
- HDU6025 Coprime Sequence —— 前缀和 & 后缀和
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6025 Coprime Sequence Time Limit: 2000/1000 MS (Java/ ...
- bootstrap历练实例:复选框或单选按钮作为输入框组的前缀或后缀
<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content=&q ...
- bootstrap历练实例:按钮作为输入框组前缀或后缀
<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content=&q ...
随机推荐
- Tomcat:配置虚拟目录或主目录
为了在访问web服务的时候,不需要输入项目名,直接"/"就可以访问的话,需要设置虚拟目录或在ROOT下直接放项目 1.采用虚拟目录的方式 在Host中添加 <Context ...
- 转:C语言字符串操作函数 - strcpy、strcmp、strcat、反转、回文
转自:C语言字符串操作函数 - strcpy.strcmp.strcat.反转.回文 C++常用库函数atoi,itoa,strcpy,strcmp的实现 作者:jcsu C语言字符串操作函数 1. ...
- Sqlerver_各类函数
SQL Aggregate 函数 SQL Aggregate 函数计算从列中取得的值,返回一个单一的值. 有用的 Aggregate 函数: AVG() - 返回平均值-SELECT AVG(colu ...
- Android menu 简单创建
在android 中与menu相关的类有4个: Menu:菜单的父窗口,用于创建一个菜单,是subMenu,ContentMenu,MenuItem等的父接口:SubMenuyo用于创建子菜单,Con ...
- vim 空格和换行的删除和替换
%s/\s//g %s/\r//g %s/\n//g 把一个很长的一行按空格分为多行 :%s/ +/\r/g简单解释一下:%s :在整个文件范围查找替换/ :分隔符+ :匹配空格,其中“ ”表 ...
- php学习记录 易混淆
1.echo和print的区别 PHP中echo和print的功能基本相同(输出),但是两者之间还是有细微差别的.echo输出后没有返回值,但print有返回值,当其执行失败时返回flase.因此可以 ...
- Perl 语法 - 高级特性
总结: q().qq().qw(同单引号).qx{牢记是花括号},分别是单引号.双引号.创建字符串列表 和 捕获命令输出. 第9学时 其他函数和运算符 一件事情可以使用多种方法完成. 有哪些其他的 ...
- SwitchCompat 修改颜色
Ok, so I'm sorry but most of these answers are incomplete or have some minor bug in them. The very c ...
- 显示win7桌面网络.reg
显示win7桌面网络.reg Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\C ...
- iOS 沙盒(sandbox)机制和文件操作
本文参看了 http://www.uml.org.cn/mobiledev/201209211.asp#1 这篇文章中的介绍,尊重原著. 1.IOS沙盒机制 IOS应用程序只能在本应用程序中创建的文件 ...