* Wu Shaohua:
1. As we know usually we should not define a constructor as inline.
I don't know that; it must be something new that I'm not aware of...
I also
learned if we define a member function inside the class this member function
will be automatically be inline'ed.
No, it won't. It's the same as declaring it 'inline'. Which does not
guarantee inlining.
My question is:
If I define a constructor (including its body) or another large member
function inside the class, the constructor or the member function is inline
or not? why?
Any member function definition inside the class definition is equivalent
to an 'inline'-declared definition outside the class. One possible
reason it is like that is the usual physical packaging of C++ code,
where class definitions are provided in header files that are physically
included by other files. So without the rule you'd violate the one
definition rule; what 'inline' tells the compiler is that you have
ensured that all definitions (which come from including that header) are
identical, not in conflict with each other.
2. I learned that if the member function is big we should not define it as
inline. Can anyone tell me how large that a member function should not be
inline? I suppose it depends on different compiler. I want to know clearly
when I should use inline and when should not.
You should use member function definitions inside the class definition
when that makes the code more clear.
You should provide an 'inline' external definition when that makes the
code (or e.g. the build process) more clear.
To influence actual /inlining of the machine code/, which is something
else entirely, you have to use compiler-specific means, and anyway, as a
novice you shouldn't even think about it: "premature optimization is the
root of all evil", and regarding inlining it will be pure chance if you
manage to do better than the compiler would without interference.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?