As i said in the title i want to know if is an error to include .cpp files in their respectively .h
I'm compiling using cygwin on windows. The g++ compiler was installed in cygwin using apt-cyg install g++
.
Then i added the cygwin path to env and now the g++ command is reachable from a windows cmd.
Here's a basic example to reproduce the problem.
main.cpp
#include <iostream>
#include "tezt.h"
int main(int argc, char const *argv[])
{
tezt();
return 0;
}
tezt.h
#ifndef TEZT_H
#define TEZT_H
void tezt();
#endif
tezt.cpp
#include <iostream>
#include "tezt.h"
void tezt()
{
std::cout<<"tezt"<<std::endl;
}
If i compile using simply g++ main.cpp
i get errors.
So in order to compile correctly i should type g++ main.cpp tezt.cpp
or define libraries.
It can be a trivial task when managing with multiple .cpp files stored in different folders.
So i'm proposing this approach:
if i modify the content of tezt.h, like follow, compilation is successfully! It can be a good "workaround" or it's not recommended? It's a colossal stupidity?
#ifndef TEZT_H
#define TEZT_H
#include "tezt.cpp"
void tezt();
#endif
Thanks for the attention.