首页 > 编程语言 > 详细

[C++] 基础知识点:namespace

时间:2014-11-02 19:43:29      阅读:289      评论:0      收藏:0      [点我收藏+]

Show the code:

#include<iostream>
using namespace std;
namespace CounterNameSpace {
int upperbound;
int lowerbound;
class Counter {
    int count;
public:
Counter(int n) {
    if (n <= upperbound) {
        count = n;
    } else {
        count = upperbound;
    }
}

void reset(int n) {
    if (n < upperbound) {
        count = n;
    }
}
int run() {
    if (count > lowerbound) {
        return count--;
    } else {
        return lowerbound;
    }
}
};
}
int main() {
CounterNameSpace::upperbound = 100;
CounterNameSpace::lowerbound = 0;
CounterNameSpace::Counter obj1(10);

int i;
do {
    i = obj1.run();
    cout << i << ",";
} while (i > CounterNameSpace::lowerbound);
cout << endl;

return 0;
}

[C++] 基础知识点:namespace

原文:http://my.oschina.net/beloser/blog/339983

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!