Can you use the same function name for a member functoin of a class and an outside function in the same program file?

1 answer

Answer

1228714

2026-08-27 19:00

+ Follow

Yes you can use the same function name for a member function and an external function. They are primarily distinguished by the number and type of arguments they accept (the function signature). If they match exactly, then the scope resolution operator (::) is used to differentiate them by namespace. The class namespace is the class name itself. The external function uses global scope unless scoped to another namespace. When the scope is not explicitly stated, then the scope is implied by the call site.

Note that whenever there is any ambiguity about which function is implied, the compiler will emit an error indicating where the ambiguity lies, and the program will ultimately fail to compile.

ReportLike(0ShareFavorite

Copyright © 2026 eLLeNow.com All Rights Reserved.