One of these days, a fellow user commented on another question of mine: "Everything that you call declarations in your code are actually definitions". I decided to take some time in order to understand the difference between both concepts.
Considering the code below:
test.hpp
class Test
public:
Test();
};
test.cpp
#include "test.hpp"
Test::Test()
{
// code
}
main.cpp
#include "test.hpp"
int main()
{
Teste objTest = Test();
return 0;
}
Question 1: From my understanding, the header file test.hpp defines a class named Test
(based on this answer). Is that correct?
Question 2: My code is based on a common practice (I've seen a number of open-source libraries following that pattern), which seems to be against the rule "headers should contain only declarations; all definitions should be in .cpp file". But is it acceptable? If not, how exactly should one write class declarations/definitions properly?