zoukankan      html  css  js  c++  java
  • 变量及对象的作用域

    代码

    #include 
    <iostream>
    using namespace std;

    class Scope
    {
    public:
        Scope(
    const char* infor);
        
    ~Scope();
    private:
        
    char information[40];
    };

    Scope::Scope(
    const char* infor)
    {
        strncpy_s(information,infor,
    40);
        cout 
    << "Constructor called for " << information << endl;
    }

    Scope::
    ~Scope()
    {
        cout 
    << "Destructor called for " << information << endl;
    }

    void function()
    {
        Scope localScopeInFunction(
    "LocalScopeInFunction");
        
    static Scope StaticScopeInFunction("StaticScopeInFunction");
        Scope 
    *scope = new Scope("ScopeInFunctionOnHeap");
        cout 
    << "In function()" << endl;
    }

    Scope GlobalScope(
    "GlobalScope");

    void main_scope()
    {
        Scope scopeInMain(
    "ScopeInmain");
        Scope 
    *scope = new Scope("ScopeInMainOnHeap");
        cout 
    << "In Main before call function()" << endl;
        function();
        cout 
    <<"In Main after call  function()." << endl;
    }



  • 相关阅读:
    Pandas获取本地csv文件到内存中
    波士顿房价数据集可视化
    tensorflow之数据集调用(波士顿房价数据集)
    查单词
    censoring
    字符串大师
    Parity game
    前缀和
    String
    Seek the Name, Seek the Fame
  • 原文地址:https://www.cnblogs.com/flaaash/p/1895122.html
Copyright © 2011-2022 走看看