zoukankan      html  css  js  c++  java
  • c++命名空间namespace

    namespace 变量作用域的作用空间,这样可以防止相同名称的变量被调用时带来的问题
    #include "iostream" #include <string> using namespace std; namespace coachnamespace { string coachname = "陈培昌"; class mycoach { private: string name; int age; public: void myfunc(string _name, int _age) { name = _name; age = _age; cout << "大家好,我是" << name << "今年" << age; } }; } namespace studentnamespace { string name = "saintding"; namespace smspace { string fv1 = "散打"; string fv2 = "巴西柔术"; } namespace normalspace { string f1 = "买书"; string f2 = "吃大餐"; string f3 = "花钱"; } } void main() { using namespace coachnamespace; using namespace studentnamespace; studentnamespace::name; string _fv1= studentnamespace::smspace::fv1; cout << studentnamespace::name << "喜欢玩荤的" << _fv1 << endl; coachnamespace::mycoach mc; mc.myfunc("程劲",20); system("pause"); } 去掉.h的理由,早期引用头文件导致程序运行速度很慢
  • 相关阅读:
    THINKPHP3.2视频教程
    PHPCMS 学习
    PHPCMS 后台学习
    phpcms 模板学习
    二叉树的创建与遍历(链式存储)
    MySQL基础~~增、删、改、简单查
    队列的基本操作(链队列)
    MySQL基础~~表结构操作
    行编辑程序
    循环链表的基本操作
  • 原文地址:https://www.cnblogs.com/saintdingspage/p/10358564.html
Copyright © 2011-2022 走看看