I have an interview, the interviewer asked me a question about const and static keyword in C++; The question is why you cannot define a member function like this:
static void func() const
He mentions somewhat *this = null causes this problem, I just did not get his idea, he didn't talk in detail.
The trailing const qualifier is applied to the this pointer that is passed as an implicit argument to each non-static member function. Since the function in question is static, there is no this pointer that could be qualified so the construct is bogus.
The const keyword is used to prevent you from modifying the object that the method is called against. Static methods aren't called against an object, so it doesn't make sense to include them both.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With