Behavior of decltype

后端 未结 3 1487
感情败类
感情败类 2020-12-10 04:53

Say I have an object of some of stl container classes obj. I can define other object of same type this way:

decltype(obj) obj2;
<
3条回答
  •  天命终不由人
    2020-12-10 05:15

    Your code is well-formed according to the final C++0x draft (FDIS). This was a late change that's not yet been implemented by the Visual Studio compiler.

    In the meantime, a workaround is to use a typedef:

    typedef decltype(obj) obj_type;
    obj_type::iterator it = obj.begin();
    

    EDIT: The relevant chapter and verse is 5.1.1/8:

    qualified-id:
        [...]
        nested-name-specifier templateopt unqualified-id
    
    nested-name-specifier:
        [...]
        decltype-specifier ::
    
    decltype-specifier:
        decltype ( expression )
    

    And for completeness's sake:

    The original core issue

    Proposal for wording

提交回复
热议问题