I'm a noob to C++ and mainly used scripting languages like python to get by. Compiling languages are new to me and I am having a hard time understanding #include
, headers, and so on.
I was recently trying to write a program with a class, called Point.cpp
. So, I tried including this class into my main file by #include "Point.cpp"
. This prompted an error saying that the constructors were defined multiple times. A StackExchange post addressed a similar problem and advised to include the header instead. This time the code compiled without a problem and worked as expected.
It seems strange that this would work because I have already included "Point.hh"
into Point.cpp
, so it seemed logical (transitive) to include Point.cpp
into main.cpp
.
Can someone weigh in on this? I would like to understand this better. Thanks.