开发者

Ambiguity Resolution

void S(){}
struct S{};

int main(){
   S开发者_开发问答();
}

In the code above, the expression 'S()' in main is treated as a function call expression rather than an attempt to create a temporary of type 'S'.

Which portion of the C++ Standard talks about the resolution of such an expression in favour of a function declaration? For some reason I am unable to locate it.


Section 3.3.7/2

A class name (9.1) or enumeration name (7.2) can be hidden by the name of an object, function, or enumerator declared in the same scope. If a class or enumeration name and an object, function, or enumerator are declared in the same scope (in any order) with the same name, the class or enumeration name is hidden wherever the object, function, or enumerator name is visible.

Then you need to use elaborated type specifier in such cases

3.4.4/1 Elaborated type specifiers

An elaborated-type-specifier may be used to refer to a previously declared class-name or enum-name even though the name has been hidden by a non-type declaration (3.3.7). The class-name or enum-name in the elaborated-type-specifier may either be a simple identifer or be a qualified-id.


It can be resolved either by using the scope resolution operator(::) or by using virtual keyword(when we are dealing with either multiple or hybrid inheritance.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜