static

17 篇文章 1 订阅

#include <iostream>

using namespace std;

int static staticNum = 3;

int globalNum = 4;

struct staticClass
{
    static int staticClassNUm ;
    int classNum = 6;

    int getClassNum()
    {
        return staticClassNUm;
    }

    static int getStaticClassNum()
    {
        return staticClassNUm;
    }
};

int staticClass::staticClassNUm = 5;

struct constClass
{
    const int a = 40;

    int getB()
    {
        return b;
    }
private:
    const int b =50;
};

void funcTest()
{
    static int staticFuncNum = 7;
    staticFuncNum = staticFuncNum + 1;
    int Num = 10;
    Num = Num + 1;
    printf("staticFuncNum:%d \n", staticFuncNum);
    printf("funcNum:%d \n", Num);
}

void static getInt()
{
    static int a1 = 12;
    a1 += 1;
    cout <<a1<<endl;
    int a2 = 20;
    a2 = a2+1;
    cout <<a2<<endl;
}

const int getConst()
{
    return 21;
}

int main()
{
//    staticClass a;
//    cout <<"staticNum:"<<staticNum<<endl;
//    cout <<"globalNum:"<<globalNum<<endl;
//    cout <<"staticClassNUm:"<<staticClass::staticClassNUm<<endl;
//    cout <<"getjClassNUm:"<<a.getClassNum()<<endl;
//    cout <<"getStaticClassNum:"<<a.getStaticClassNum()<<endl;
//    funcTest();
//    funcTest();
//    getInt();
//    getInt();
    //cout << 0 << endl;
    int constNum  = getConst();

    constNum = constNum + 1;//22
    constClass c;

    cout <<c.a <<endl;
    cout <<c.getB() <<endl;
    cout <<constNum<<endl;
    getchar();
    return 0;
}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值