Curiosity: including .cpp files
This isn't related to any problem I'm having, but I'd like to understand this issue once and for all.
When people do something like:
Code:
#include "myfile.cpp"
I often see replies saying "you can't include .cpp files. Only header files!"
I beg to differ. Here's a little example I prepared:
hellomain.cpp code
Code:
#include <iostream>
#include "helloworld.cpp"
using namespace std;
int main() {
helloWorld();
cin.get();
return 0;
}
helloworld.cpp code
Code:
#include <iostream>
using namespace std;
void helloWorld();
void helloWorld() {
cout << "Hello World!" << endl;
}
Assuming both .cpp files lie in the same directory, I can compile and execute hellomain.cpp just fine! I don't even need to create a project file in Dev-C++ for this to work!
So the question is... Is there something I'm missing? Why exactly do people say we can only include header files? Is it something else I should know?
Looking forward to your replies.