Ok so I just started working with making classes into files. Working on a friend operator I came into a problem, headers in .h files. For some reason when I add headers for other classes in my .h files it either breaks or fixes my errors. I would like an explanation for the right and wrong ways to use headers instead of trying them randomly until the program works.
For example:
CLASS 1 .H FILE
#ifndef CLASS1_H
#define CLASS1_H
#include <stdio.h>
// if i put #include "Class2.h" here this breaks the code WHY!?
class Class1
{
public:
Class1();
protected:
private:
int var=10;
friendclass Class2;
};
#endif
CLASS 2 .H FILE
#ifndef CLASS2_H
#define CLASS2_H
#include "Class1.h" // Without this here, program breaks(error class 1 not defined in scope) why?
#include <stdio.h>
class Class2
{
public:
void getVar(Class1 obj);
};
#endif