c++实例研究

从0开始

  C++博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  104 随笔 :: 0 文章 :: 20 评论 :: 0 Trackbacks
#include <iostream>
#include 
<cstdlib>
using namespace std;

class Foo
{
public:
    Foo(
int ii):i(ii){}
    
int getInt(){return i;}
private:
    
int i;
}
;

class Bar
{
public:
    
static int FooVal(){c++return f.getInt();}
    
int callsFooVal(){return c;}
    
int setValb(int bb=c){b=bb;return 0;} //可变的默认值 
    int show(){return b;}
private:
    
int b;
    
static int c;
    
static Foo f;
}
;

int Bar::c=0;
Foo Bar::f(
9);

int main()
{
    Bar b;
    cout
<<Bar::FooVal()<<endl; 
    cout
<<b.callsFooVal()<<endl;   
    cout
<<b.setValb()<<endl;
    cout
<<b.show()<<endl;
    cout
<<"---------"<<endl;
    cout
<<Bar::FooVal()<<endl; 
    cout
<<b.callsFooVal()<<endl;
    cout
<<b.setValb()<<endl;
    cout
<<b.show()<<endl;  
    cout
<<"---------"<<endl;
    cout
<<Bar::FooVal()<<endl; 
    cout
<<b.callsFooVal()<<endl; 
    cout
<<b.setValb()<<endl;
    cout
<<b.show()<<endl;
    cout
<<"---------"<<endl;
    system(
"PAUSE");
    
return 0;
}

posted on 2010-04-26 20:48 elprup 阅读(528) 评论(0)  编辑 收藏 引用 所属分类: c++实例

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理