In C++, is the return type considered part of the function signature? and no overloading is allowed with just return type modified.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Normal functions do not include the return type in their signature.
(note: i’ve rewritten this answer, and the comments below don’t apply to this revision – see the edit-history for details).
Introduction
However, the matter about functions and function declarations in the Standard is complicated. There are two layers that have to be considered:
The so-called function declaration may declare a function entity or a template entity. If a function entity is declared, then you either have to do with an explicit specialization of a function template (with all arguments specified), or a declaration of an ordinary function. If a template entity is declared, then you are declaring a primary function template, or an explicit specialization where some arguments are not specified. (This is very similar to the relation of "object declaration" and objects or references: The former may declare either an object or a reference. So an object declaration may not necessarily declare an object!).
The Standard defines the signature of a function to include the following at
1.3.10:It’s missing the return type in this definition, which is part of the signature of a function template specialization (i.e a function declaration that declares a function which is a specialization of a template), as pointed out by
14.5.5.1(recent C++0x working papers fixed that already to mention the return type in1.3.10too):So what exactly does a signature contain, again?
So, when we ask about the signature of a function, we have to give two answers:
Notice, however, that the return type, in any case, is a significant part of the type of a function. That is, the following is not valid:
When is an overload invalid if only the return type differs?
Major compilers currently reject the following code:
But accept the following code:
However, the Standard does forbid a function declaration that only differs in the return type (when defining when an overload is valid, and when not). It does not define precisely what "differs only by return type" means, though.
Standard paragraph references:
13.17/2and7/514.5.5.1For reference, here is what the most recent C++0x draft n3000 says about "signature" in
1.3.11, which is much more complete in its coverage of the different type of entities: