#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;
}
类的作用域
最新推荐文章于 2021-12-28 12:25:25 发布