Reputation: 349
If a function with the same name is defined in multiple files with a different signature, are these overloaded eg.
File1.cpp
int foo(){//do something}
File2.cpp
int foo(int a){//do something}
If I compile both these files in the same project, will these functions be treated as overloaded functions.
Upvotes: 0
Views: 76
Reputation: 8576
Yes, they will be appropiately name-mangled into two separate functions whose scope is global, at the global namespace (a.k.a: the ::
namespace).
For two functions to be overloaded, and not violate the ODR, their parameter types and "attributes" (such as const
, volatile
, or noexcept
after the argument list) shall be different. Two functions with the same set of parameter types and "attributes", but with different return type violate the ODR.
Just don't worry about this, and let the linker be the slave of the compiler it was born to be.
Upvotes: 0
Reputation: 409136
Yes they are two different functions.
A functions signature is primarily based on the arguments: The number of arguments, their types and the order. Class member functions also have modifiers, like const
or not. Return type is not part of the signature to distinguish between overloaded functions.
If two functions of the same name have unique signatures, then they are different.
Upvotes: 2