Variable name same as function name giving compiler error... Why?

The local variable overwrites the designator for the method in the local block. Try this->function1() to call it nevertheless.

Or better yet, rename the one or the other to help people reading your code avoiding confusion (and this includes your future yourself).


To answer your question: "Should this be allowed":

In c++ you can have different entities with the same name if they exist in different scopes (like in your example). This is very useful feature in general, because it allows you to use whatever names you like for your entities assuming that you provide them in scope e.g. in namespace. Said that, compiler needs some algorithm to select entity when it sees name in code. In c++ standard process of matching name to declaration is called 'name lookup'. You can see description of this algorithm e.g. here cppreference or directly in standard draft.