I am coding a minesweeper game and I am currently splitting declarations and code between header and cpp files like you're supposed to, however, this is making it kind of convoluted to keep track of everything.
I know this is against best practices, but could I just declare and code everything on cpp files and then split them up into their respective files at the end? Would this mess up anything inside Visual Studio 2019? I feel like it shouldnt but ive had linker problems with VS code in the past and I havent been able to fix them (one of the reasons why I use visual studio for cpp now) so I just want to make sure before I do something thats going to bite me later on.
Any insight is appreciated. I know its a lazy way to cope with the problem but Im just trying to get this done quickly.
CodePudding user response:
There's nothing that prevents you from having one monolithic .cpp. However, those of us with experience will probably tell you that's a mistake.
One of the cool things about C is that it encourages you to organize your code. It encourages you to think about how things are related, and to group like things together.
This shouldn't be convoluted. The header files contain declarations. The cpp files contain implementations. You name them to match. IOSystem.h and IOSystem.cpp go together.
CodePudding user response:
Declaring and coding everything on cpp files will cause error lnk2005
. Putting it all in the header file won't cause the error, although this is also against best practices. But it all depends on personal writing style.In addition, code should be easier for others to read and understand. And It's a good choice to follow experienced people's coding style.