Accessing attribute of object

Hi I have a scenario like this:

Outer.h--->
Outer{
Foo* f;
Bar* b;
}

Foo{
int a;
float b;
}

Then, In Outer.cxx I want to create object b of Bar such that it can use the member variables of f in the constructor.
Like the constructor for Bar would look something like Bar* b = new Bar(f->a);

Can I do something like this? Can I access the member functions of f when creating b?
Can I do something like this? Can I access the member functions of f when creating b?
Yes
Thanks.
Also, Can I access the member variables of f when creating b?
You can access any member (no matter if variable or function) of an existing object (if this member is accesible, i.e. public)

But you need an object:
1
2
Outer o;
Bar* b = new Bar(o.f->a);


You do not need an object if that member is static:
1
2
3
4
5
Outer{
static Foo* f;
Bar* b;
};
Bar* b = new Bar(Outer::f->a);
But then I need to ensure that I create object f before I create b right?
for the non static case: yes
Topic archived. No new replies allowed.