How Do I Pass Two Objects to be Stored in Another object by reference?

I have classes A, B and C stored inside an object, X. I want to pass class A and B by reference to class C because class C needs to use some functions inside classes A and C. How do I do this?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class X
{
    public:
    // functions
    private:
    A a;
    B b;
    C c;

// in .cpp
X::X()
{
    // How do I pass A and B to C here? I could either make a constructor for
    // C that takes a reference to an A or B, or two functions that do it.
}
What about
 
c::myfunc(a, b);

What is wrong with that?
Hi,

I am guessing you meant C needs to use functions in A and B.

Can you give a brief run down on what is the real life situation here? Just want to check that the design is valid - it may or may not be OK. There might be other ways of achieving this.

When you say "C needs to use some functions inside classes A and sic[C] B." : What do you mean exactly? Does C call a function in A using C's private data? What does the public interface of these 3 classes look like? Could the public interface be used to retrieve data from one class object , then send it to another class function via that class' interface?

You could make class C a friend of classes A and B. This would give class C full access to all of A and B , and could be overkill. http://en.cppreference.com/w/cpp/language/friend

From a function in X (not X's constructor), call a function in C that has arguments a and b.

Topic archived. No new replies allowed.