I have a large class the has over 10 member functions, assume i name it CCar. What is better way to create the object?
CCar example1;
example1.burnFuel();?
Or
CCar *example2;
example2 = new CCar();
example2->burnFuel();?
1. I know the pointer is better, but is it good to use always (Assume i have 7 large classes)? If no, why?
2. How can i make my pointer points to the function, but with guaranteeing that no changes can be made by mistake? I know i have to put const somewhere when creating the object, can you show the proper way? I want to ensure example2 does not change anything in burn fuel, if it did, i should get compiler error.
3. When i include the header #include"CCar.h", the preprocessor will resolve all the header, etc, then program will start compiling. When pre-processor resolved all the headers, does not this increase the size of the current file? If yes, then whats the point of using objects as a pointer because we already copied whats in headers into our current file! right? Is there a way we can make include points to CCar.h?
4. When pre-processor deals & bring all the code in CCar.h into the current file, what happens to the implementation CCar.cpp?
5. In the implementation CCar.cpp we must include CCar.h & every definition function header will have a scope void CCar::burnFuel() {......}. Rgiht? OK, when we include CCar.h into main() as an example, then how CCar.h will believe its already have CCar.cpp (CCar.cpp by itself needs to include CCar.h, so main() as well will need to have a definition for CCar.h declaration). In other words, how can CCar.h in main() know that its already been definied in CCar.cpp while CCar.cpp needs to include CCar.h & the scope. So when you include CCar.h in main() how CCar.h can judge that it already been defined?
6. Based on question 5, what if i make two implementation for CCar.h? Will this work? Why?
Just feel free to answer any question you know its answer...
I hope to hear from you...
ASKER