user4332856
user4332856

Reputation:

Pass by reference in C++?

I am having trouble getting one class to recognize another class exists. I believe this is pass by reference, but I'm not sure.

class A{
public: 
A(B b);
};

class B{
public:
B(A a);
};

In class B the constructor of B recognizes I'm passing A but in class A I keep getting a

Type 'B' could not be resolved

error.

Upvotes: 0

Views: 86

Answers (1)

user229044
user229044

Reputation: 239311

This has nothing to do with "passing", by reference or otherwise.

The issue is that class B has not been declared at the point when you try to use it in class A.

You need a forward declaration of class B:

class B;

class A{
public: 
    A(B b);
};

class B{
public:
    B(A a);
};

Upvotes: 3

Related Questions