#include <cstdio>
#include <iostream>
using namespace std;

class TmpClass;
void FuncScopeTmpClass(TmpClass s);

class TmpClass{
public:
    TmpClass():ident(i--){ printf("%2d ++\n", ident); }
    ~TmpClass() { printf("%2d --\n\n", ident); }
    int tick() { printf("%2d ||\n", ident); return i; }
private:
    int ident;
    static int i;
    friend void FuncScopeTmpClass(TmpClass s);
};

int TmpClass::i = 20; 

TmpClass GetTempClass() { return TmpClass(); } 

void FuncScope(int s) { printf("%2d >>\n", s); }
void FuncScopeTmpClass(TmpClass s) { printf("%2d <<\n", s.ident); }

int main() {
    while(GetTempClass().tick()) {
        TmpClass a, b;
        GetTempClass(), GetTempClass(), FuncScope ( GetTempClass().tick() );
        FuncScope ( GetTempClass().tick() ), GetTempClass();
        FuncScope ( GetTempClass().tick() );
        FuncScopeTmpClass ( (GetTempClass(), GetTempClass(), GetTempClass()));
        break;
    }; return 0;
}
/* standard output
20 ++
20 ||
20 --

19 ++
18 ++
17 ++
16 ++
15 ++
15 ||
14 >>
15 --

16 --

17 --

14 ++
14 ||
13 >>
13 ++
13 --

14 --

12 ++
12 ||
11 >>
12 --

11 ++
10 ++
 9 ++
 9 <<
 9 --

10 --

11 --

18 --

19 --
*/

cpp-variable-lifetime的更多相关文章

  1. jbpm的学习 出处http://blog.csdn.net/hxirui/article/details/1221911

    jbpm入门例子 分类: opensourse2006-09-14 11:30 37308人阅读 评论(22) 收藏 举报 jbpmhibernate数据库oraclemysqltransition ...

  2. jbpm入门样例

    1.      jBPM的简介 jBPM是JBOSS下的一个开源java工作流项目,该项目提供eclipse插件,基于Hibernate实现数据持久化存储.    參考 http://www.jbos ...

  3. 【LINT】cpplint修改版:自定义编码风格检查工具lint

    github:https://github.com/skullboyer/code-check Code Check 本仓介绍的内容涉及代码静态检查和编码风格检查 但主要放在编码风格检查,lint是基 ...

  4. OPEN CASCADE Multiple Variable Function

    OPEN CASCADE Multiple Variable Function eryar@163.com Abstract. Multiple variable function with grad ...

  5. vs2012 error c4996: This function or variable may be unsafe

    编译lua源码时,使用vs2012,遇到如下错误. 1>------ 已启动生成: 项目: 20130925, 配置: Debug Win32 ------ 1>  stdafx.cpp ...

  6. 配置OpenCV产生flann\logger.h(66): error C4996: 'fopen': This function or variable may be unsafe问题[zz]

    使用vs2012/2013配置opencv编译出现问题: 1>------ 已启动生成: 项目: Win32ForOpenCV245, 配置: Debug Win32 ------ 1> ...

  7. 安装solidity遇见的问题——unused variable 'returned'

    在编译安装solidity的过程中遇见了一个很奇怪的问题 webthree-umbrella/libethereum/libethereum/Executive.cpp: In member func ...

  8. [C/CPP系列知识] 那些程序C语言可以编译通过但C++无法编译成功 Write a C program that won’t compile in C++

    http://www.geeksforgeeks.org/write-c-program-wont-compiler-c/ 1) C++中在函数声明之前调用一个函数会引发错误,但是在C中有可能可以. ...

  9. Visual Studio 2015 编译错误【错误 C4996 'vsprintf': This function or variable may be unsafe. Consider using vsprintf_s instead. 】的解决方案

    错误提示信息: 错误 C4996 'vsprintf': This function or variable may be unsafe. Consider using vsprintf_s inst ...

  10. Run-Time Check Failure #2 - Stack around the variable 'ucPriKey' was corrupt

    Run-Time    Check    Failure    #2        一般是栈被破坏,你的代码可能有缓冲区溢出一类的问题. Run-Time Check Failure #2 - Sta ...

随机推荐

  1. SVN那些事

    非原创,引用于青松世界博客,最近在使用svn,因为方便复制内容在这查看.原地址 https://www.cnblogs.com/Rambo635755402/p/5549447.html Totois ...

  2. mvc, web mvc, spring web mvc 区别

    1. MVC全名是Model View Controller,是模型(model)-视图(view)-控制器(controller)的缩写,一种软件设计典范,用于组织代码用一种业务逻辑和数据显示分离的 ...

  3. JAVA反射机制教程-获取类对象

    1. 什么是类对象 类对象,就是用于描述这种类,都有什么属性,什么方法的 2. 获取类对象 获取类对象有3种方式(1). Class.forName(2). Hero.class(3). new He ...

  4. S1 商品信息管理系统

    #include <iostream> #include <cstdio> #include <cstdlib> #include <iomanip> ...

  5. jQuery.fn.extend()

    jQuery.fn.extend() extend()方法是定义在jQuery构造函数的prototype对象上面的一个方法,这样做就能使得所有jQuery对象的实例都能共享这个方法.jQuery构造 ...

  6. 在centos7上搭建博客之小白教程~

    原理 http使用方法一编译安装,php模块打入方式实现. 软件版本 在本次实验中,我们需要用到的软件版本如下: apr-1.6.2 apr-util-1.6.0 httpd-2.4.28 maria ...

  7. 配虚拟ip脚本

    cat /home/master/init_pandora.sh #! /bin/shuser=`whoami`if [ $user = 'master' ]then sudo /sbin/ifcon ...

  8. kubenetes 1.9 学习 pod - volume -- dashboard

    kubelet: the component that runs on all of the machines in your cluster and does things like startin ...

  9. hibernate -- 注解映射实体和表

    表名的映射 //代表此类参与ORM映射,此注解必须要有 @Entity //代表user这个类映射了一个表user50,如果表名和类名一样,此注解可以省略 @Table(name="user ...

  10. Quartz.NET+Topshelf 创建Windows服务

    由于项目开发中经常会有定时任务执行的需求,所以会第一时间就想到 windows 服务 的方式,但是做过开发的同学都知道windows服务不利于调试,安装也麻烦: 并且有开源的作业框架Quartz.NE ...