I make my own header files in my free time for my own use. For eg. I made luint.h for handling very large integers and ekumath.h for some useful math functions.
I've seen some people on the internet talk about something like 'splitting interface and implementation' or 'splitting declaration and implementation'. They say that .h files should only be used for declaration and implementation should be in a .cpp file.
If I write the implementation in the .cpp file, how will my main code know about it? I will either have to include the .cpp file in my project or #include it. But these ideas seem to defeat the purpose. I think it should work like the C libraries; just #include the header file and you have the implementation (whether it's binary or .cpp).
Can anyone please explain this concept with its advantages or disadvantages?
and you've put implementation (i.e. the do_nothing() implementation) in the header file? So you're giving OP an example of what not to do? Makes more sense then I guess.
I made luint.h for handling very large integers and ekumath.h for some useful math functions.
I've seen some people on the internet talk about something like 'splitting interface and implementation' or 'splitting declaration and implementation'. They say that .h files should only be used for declaration and implementation should be in a .cpp file.
I assumed he made both declaration adn implementation in a single file, so i wrote:
Main problem with having interface and implementation in one file arises when you need to use your header in more than one file
[...]
Linker will throw an error that function do_nothing() declared twice: in main.cpp and secondary.cpp
I made an example where that approach will lead to some errors which can be hard to catch.