Originally Posted by
3321thec
Well, I guess what it comes down to is, I need to know how to access members of a seperate class (ie Buttons ect.)
Class or Object? If class, you probably mean static members.
Code:
ClassName::memeber(<param>);
If object, you need to have a reference to that object to be able to use it's funtions.
Code:
class B
{
public:
void member_of_B()
{
cout << "B here!\n";
}
};
Class A
{
B& b_ref;
public:
A(const B& reference_to_B_object)
: b_ref(reference_to_B_object)
{}
void use_member_of_class_B()
{
b_ref.member_of_B();
}
};
int main()
{
B b; // create B object
A a(b); // create A object and pass it a reference to the object of class B from above
a.use_member_of_class_B(); // A accesses a non-static member of class B
return 0;
}
or place A and B in a stronger (has-a) relation:
Code:
class B
{
public:
void member_of_B()
{
cout << "B here!\n";
}
};
Class A
{
B b;
public:
A()
: b()
{}
void use_member_of_class_B()
{
b.member_of_B();
}
};
int main()
{
A a; // create A object whose constructor creates a B object
a.use_member_of_class_B(); // A accesses a non-static member of class B
return 0;
}