Here is the situation. I have two classes inside two different files.
A.cpp:
#include "B.h"
A::A(){
B foo; //B doesn't name a type
}
B.cpp:
Class B{
//code
};
How do I correctly construct an object of B inside A’s constructor?(scoping issue) I tried
B::B foo //wrong
and why I can’t directly construct an object of class B like I did above, B.h has been included. Thank you very much
Put the class definition of
Binto the header file:b.h:
a.cpp:
b.cpp:
If there’s nothing in class
B, you can omitb.cppand put the entire class definition into the header file.