【发布时间】:2011-07-14 13:13:15
【问题描述】:
用另一个类(内部类)的方法编写的类可以访问方法变量吗?我的意思是在下面的代码中:
class A
{
void methodA( int a )
{
class B
{
void processA()
{
a++;
}
};
std::cout<<"Does this program compile?";
std::cout<<"Does the value of the variable 'a' increments?";
};
};
这合法吗?'a' 的值会增加吗?请提出建议。
谢谢, 帕万。
【问题讨论】:
-
comeaucomputing.com/tryitout "第 9 行:错误:不允许引用封闭函数的局部变量"
-
实际上,我在一个远程位置,我在这个 m/c 中没有编译器 :(
-
@user844631 - 查看ideone.com - 以您选择的语言运行小型代码示例的好网站。
标签: c++ nested-class