for single .cpp file- and .h file- we can move implementation from .cpp to .h file, but i can not do this for my case and occurred circularity :
my case is something like this (inclusion guard ignored):
//a.h
#include"stdio.h"
#include"b.h"
class A
{
public:
void showfromA(const B& b);
int index;
};
//a.cpp
#include"a.h"
void A::showfromA(const B& b)
{
printf("b.index=%i",b.index);
}
//b.h
class B
{
public:
void showfromB();
int index;
};
//b.cpp
#include"a.h"
void B::showfromB()
{
A a;
a.index=1;
printf("a.index=%i",a.index);
}
//main.cpp
#include"b.h"
main()
{
B b;
b.showfromB();
}
circularity occurred because a.h include b.h but b.cpp include a.h. when .h files and .cpp files are separated ,the code is OK and we do not have circularity but when we try to merge .h file and .cpp file we encounter to circularity between class A and B and compile error. note that i want to move method implantation from .cpp file into * the class definition* in .h file