I have several files which is causing a compile error, can the following be done?
header1.h
class Class1{
public:
void function1(Class1 &);
};
header2.h
class Class2{
public:
void function2(Class2 &, Class1 &);
};
cpp2.cpp
#include "header2.h"
void Class2::function2(Class2 & my2Class, Class1 & my1Class){};
main.cpp
#include "header1.h"
#include "header2.h"
// functions
The error is stating that header2.h knows nothing of Class1 as a type. How can I declare an object of type Class1 in this header file, without using an include or without putting both classes in the same file (they are entirely separate and should only meet inside functions called within main)?
Thanks!
You can use forward declarations:
Passing a parameter of a type to a function doesn’t require the type to be fully defined.