类的作用域

#include<iostream>
#include<string>

using namespace std;

class First{
public:
    int memi;//类的作用域,在别的地方不可以使用
    double memd;
public:
    void doC()
    {
        memi = 2;
    }
    void doD()
    {
        doC();
    }
};

int height;//quanju

class ScreenB{
public:
    typedef std::string::size_type index;
    void dummy_fvn(index height)
    {
        //cursor = width*width;//是传入的height
        //cursor = width*this->height;//this指针指向当前的这个类,就是私有的height
        cursor = width*::height;//现在指向全局height,四个点是全局作用域


    }
private:
    index cursor;
    index height, width;//类作用域里的height






};


class ScreenA{
public:
    typedef std::string::size_type index;//局部定义的类型别名
    char get(index r, index c) const;
    index get_cursor() const;

private:
    std::string contents;//数据成员
    index cursor;
    index height,width;
};

ScreenA::index ScreenA::get_cursor()const{

    return cursor;
}

char ScreenA::get(index r, index c) const{//必须写上作用域操作符Screen::
    index width;
    index row = r * width;
    return contents[row + c];
}
int main()
{
    ScreenA::index ht;//::作用域操作符
    First obj;
    First *ptr = &obj;
    obj.memi = 12;//可以通过对象使用memi,直接使用就不可以。

    ptr->memi = 99;
    ptr->doC();

    cout << "hello" << endl;

    system("pause");
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值