+ 1
How to make friend classes if they in different files .h
i have two classes a.h and b.h . and without .cpp files. because a code is in .h files . And i cant understand how to make them a friends. in function: public: void damage(a &obj){ obj.hp-=dmg; } Compile said me " a is not define"
4 ответов
+ 2
Did you include your a.h in b.h?
#include "a.h"
Better practise to devide class declaration (a.h) and class description (a.cpp).
+ 1
yes, i agree with you. but how to do friendly classes when i make descriptiin and declaration in same file.
when i #include a.h in b.h and #include b.h in a.h , compile said me that included class define self.
+ 1
Try to use forward declaration.
class A;
class B { ... };
class A { ... };
+ 1
yes it work when write all in one file .cpp.
is this possible by using only .h files for classes?