in my pursuit to be a great c++ programming :) i am learning now classes, files, files such as cpp and header files, i read online
to help me, and doing an example myself, i am trying to get the functions onto the other cpp file called Log, and the header file called log, and the main cpp file called... Main. so my 2 questions are:
1. how do i get the functions/methods onto the log.cpp from the Log.header file, reading the documentation, it says its best to put the functions on the Log.cpp, but declaring and putting the variables on the header, is this correct, if so how?
2. if i had like, 5-10 classes, do i put them all onto 1 header file? what would be good practice that you have seen or yourself has done in a job environment plus for performance? big thanks for taking the time to read and answer :)
1. how do i get the functions/methods onto the log.cpp from the Log.header file, reading the documentation, it says its best to put the functions on the Log.cpp, but declaring and putting the variables on the header, is this correct, if so how?
It appears that you've already moved the constructor from the definition so moving the rest of the functions would be similar.
2. if i had like, 5-10 classes, do i put them all onto 1 header file? what would be good practice that you have seen or yourself has done in a job environment plus for performance? big thanks for taking the time to read and answer :
This is really a design matter, but most of the time each class would be defined in it's own header file and implemented in it's own source file. Having the classes in one or multiple header files doesn't affect program performance, however compilation may be affected. The biggest reason to separate the classes is because it will be easier to maintain and share the code between multiple programs.
Gotya thank you jlb, sorry i am confused, so below i changed my code around so that the methods/functions are now on Log.cpp file, however on the main.cpp file, its not able to see the functions, also in the Log.cpp file, its not able to see any variables from the Log.H file, I am obviously doing something wrong :(
I got it now, big thanks :)
here is the code below for the example, let me know if there is anything i can do to make it better in terms of performance or practice please :)
You may as well move SetLevel() to the implementation file as well.
let me know if there is anything i can do to make it better in terms of performance
While performance will be important later, right now concentrate on compiling properly and producing the correct values. For now learning how to use multiple files probably overrides any concern about performance.
Gotya thanks, i will definitely remember that to keep the with the Log.cpp file, thanks, yes practice first to get things working then go back and optimize, make sense thanks :)
i removed it, didnt think it was important at the time, though i am going to learn constructors and destructors... maybe you can let me know about constructors, your thoughts of course the Log() in the class in file Log.h?