访问实例化它的类中的变量 [英] access variables in class that instantiates it
本文介绍了访问实例化它的类中的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
class B;
class A
{
public:
int x, y;
B b;
}
class B
{
func func1();
}
在func1中,如何访问在类A中定义的变量x或y?
/EDIT M-看起来像重新发布 [
In func1, how to access variables x or y defined in class A?
/EDIT M - Looks like a repost[^]
推荐答案
创建实例类A并对其进行访问.我的C ++可能有点生锈,但这就是它的精髓.
A a = new A();
a.x = ...
a.y = ...
仅仅因为您在A中有一个B实例并不意味着您可以从B中自动访问A中的任何内容.就我个人而言,我很可能将值传递给func1
func1(int x,int y)
Create an instance class A and access them. My C++ may be a little rusty, but that''s the jist of it.
A a = new A();
a.x = ...
a.y = ...
Just because you have an instance of B in A doesn''t mean you can automatically access anything in A from B. Personally I would probabably pass the values to func1
func1(int x, int y)
这篇关于访问实例化它的类中的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文