Now I see your point. I have slightly changed my example. Normally, one would put all three files in the same directory and compile:Originally Posted by anon
g++ -Wall hellomain.cpp helloextra.cpp -o helloworld.exe
(helloworld.cpp wouldn't be needed, since it's already included in hellomain.cpp)
But you're right. I get a multiple definition error if I do that.
You see, the reason I asked this is mainly because of compilers such as gcc and g++. The conventional way requires you to put all .c or .cpp files in gcc or g++, like so:
g++ -Wall hellomain.cpp helloextra.cpp helloworld.cpp -o helloworld.exe
where the three .cpp files would only include function implementations and not function prototypes. For the prototypes, one would (possibly) have to create three additional files - hellomain.hpp helloextra.hpp and helloworld.hpp with those prototypes. But then I thought: "Why do we programmers have to bother with separating function prototypes from the actual function implementations? Wouldn't it be more convenient to just store them all in single files rather than two files each?"
Really, it kind of sucks. My approach would definitely work if g++ discarded multiple definitions of functions, but I guess I'll just have to be content with what I got...