'A class has incomplete type [duplicate]
#include<bits/stdc++.h>
using namespace std;
class B;
class A{
public:
int a_i=10;
void A_lookup(B b){
cout << b.b_i <<endl;
}
};
class B{
public:
int b_i=20;
void B_lookup(A a){
cout << a.a_i <<endl;
}
};
int main(void){
A a;
B b;
a.A_lookup(b);
In this case, I have two classes both of which would visit each other members. When compiling such a .cpp file, there are two piece of information:
sample2.cpp:8:25: error: 'b' has incomplete type void A_lookup(B b){
sample2.cpp:4:7: note: forward declaration of 'class B' class B;
Why could class A still not visit the member b_i of class B after class B has been declared ahead of class A. How should I fix such a error?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
