在声明数据成员之前,成员函数中数据成员的可访问性 [英] Accessibility of data member in member function before declaration of data member

查看:220
本文介绍了在声明数据成员之前,成员函数中数据成员的可访问性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请考虑此代码:

class Test
{
public:

Test() { i = 0;  }

private:

int i;
};

甚至在声明/定义数据成员'i'之前。这应该不是编译错误? (它编译好了!)

Data member 'i' is used even before it is declared/defined. Should this not be a compilation error ? (It compiled fine!!!)

推荐答案

规则是在类定义中定义的成员函数被编译,在类定义之后立即定义。

The rule is that member functions defined in the class definition are compiled as if they were defined immediately after the class definition.

这篇关于在声明数据成员之前,成员函数中数据成员的可访问性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆