I'm trying learn c++ due to school work. Recently I've come up with a problem that stuck with me for a while. If there were 3 files, main.cpp, Fish.cpp, Fish.h
Fish.h:
#ifndef FISH_H
#define FISH_H
class Fish
{
public:
Fish();
};
#endif
Fish.cpp:
#include <iostream>
#include Fish.h
using namespace std;
Fish::Fish()
{
cout << "I love fish" << endl;
}
main.cpp :
#include <iostream>
#include "Fish.cpp"
using namespace std;
int main(){
Fish Salmon;
return 0;
}
Here comes the problem, I know if I want to use the Fish() constructor in "main.cpp", I'm supposed to include Fish.h, and then compile all 3 files, but due to curiosity, I tried to include "Fish.cpp". If I include "Fish.cpp" to "main.cpp", then everything in Fish.cpp will get copied into main.cpp, which includes the line <#include Fish.h>, right? But why every time I compile and run, the terminal gives me errors?