C++/Class and Objects
Hi, can you help me understand some class questions?
1) Must the class be declared as a global variable?
2) I understand that inline functions can be defined either inside or outside of the class block, but can normal functions do the same?
3) what exactly does inline functions do? Just speeding up the performance of the function?
4) Do the name of the constructor or destructor has to agree with that of the class?
Hello Angela, thank you for the question. I'm really sorry it's taken me so long to reply. I came down with bronchitis early last week and haven't been feeling well enough to think straight until very recently.
1) No, a class variable can be declared anywhere like any other variable.
2) Inline functions are any function defined entirely in the header. Marking the method with the inline keyword doesn't really do much good anymore, as compilers are usually better deciders of what methods should actually be inlined. So any "normal" function defined entirely in the header file is inline by definition. So the answer is yes.
3) When you include a header file with a #include directive, the preprocessor essentially "pastes" that header file inside the file that includes it. So when it's pasted, if a function is defined in the header file (inlined), it doesn't have to look up the definition of the function in the corresponding cpp file at runtime. This is a slight performance speed boost.
4) Yes. Constructor and destructor names must always match the name of the class.
I hope this was helpful, and sorry I took so long. It's been a rough week.